更改项属性时WPF ItemsControl不绑定

时间:2010-04-15 17:45:52

标签: wpf data-binding

<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>

ObservableCollection的数据源,其中过滤器在此处定义:

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");
        }
    }

当mouseleftdown事件触发时,它会调用命令(我设置了一个断点)。如您所见,它正在更新IsSelected状态。但是,界面似乎没有更新。

1 个答案:

答案 0 :(得分:0)

我将执行移动到基本控件中并且它有效。