Listview项目不可选择触发收集值数据绑定/ datatrigger

时间:2017-03-10 11:25:51

标签: c# wpf xaml listview mvvm

我有一个带有文本块的Listview来填充List,类里面是属性结果,如果我的软件能够解析文件我根据这个属性设置文本块的样式,但是我希望这个项目无法选择。

问题:

如何将ItemcontainerStyle属性IsEnabled绑定到集合的属性?

我试过了,但不起作用:

<Setter Property="IsEnabled" Value="{Binding Path=ActionResult.Result ??? doesnt work }"/>

我目前的代码:

<ListView Grid.Column="0"  ItemsSource="{Binding Files}" SelectedItem="{Binding SelectedFile}">
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="IsEnabled" Value="{Binding Path=ActionResult.Result ??? doesnt work }"/>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListView.ItemTemplate>

                <DataTemplate DataType="{x:Type model:ActionResult}">

                    <TextBlock Text="{Binding Path=Name}">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Setter Property="Foreground" Value="Black" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=Result}" Value="False">
                                        <Setter Property="Foreground" Value="LightGray" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

更新 型号:

public class ActionResult
    {
        public string Name { get; set; }
        public bool Result { get; set; }
        public object Content { get; set; }
        public string Exceptionmessage { get; set; }
    }

Files是Type ActionResult的Observablecollection

Files = new ObservableCollection<Actionresult>

以下帖子效果很好,但请参阅下面的评论。

1 个答案:

答案 0 :(得分:1)

如果Result属性属于Files集合中的数据对象,如果要在ListBoxItem属性返回{{1}时禁用Result,则此属性应该有效}}:

false
相关问题