开发者

WPF ItemsControl not binding when I change an item property

<ItemsControl Margin="0,16" ItemsSource="{Binding}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" Margin="8,0,8,18">
                    <Image Height="6" Source="MultiSelectorTick.png" Stretch="Fill" Width="4"/>
                    <TextBlock Foreground="{Binding Path=IsSelected, Converter={StaticResource ResourceKey=selectionConverter}}" 
                        Text="{Binding DisplayName, FallbackValue=Not Specified}" Margin="4,0,0,0" FontSize="13.333" >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseLeftButtonDown">
                            <MC_Windows:ExecuteCommandAction TargetCommand="ToggleExecuted"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

datasource of an ObservableCollection where filter is defined here:

private ICommand toggleExecuted;
    public ICommand ToggleExecuted
    {
        get
        {
            if (this.toggleExecuted == null)
                this.toggleExecuted = new RelayCommand(
                    e => { this.IsSelected = !this.IsSelected; });
            return toggleExecuted;
        }
    }

    public bool IsSelected
    {
        get { return this.isSelected; }
        set
        {
            this.isSelected = value;
            this.OnPropertyChanged开发者_如何学编程("IsSelected");
        }
    }

When the mouseleftdown event fires it calls the command (which works I set a breakpoint). As you can see it is updating the IsSelected state. However, the interface doesn't appear to be updating.


I moved the execution into the base control and it worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜