我有一个带有textblock的listView来填充列表,如果我的软件能够根据此属性来解析我的textblock,则在类中是属性结果,如果我的软件能够解析文件,但是,我想让这个项目不可选择。
问题:
我如何将itemContainerStyle属性绑定到集合的属性?
的属性?我尝试过,但无效:
<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; }
}
文件是类型ActionResult
的观测值Files = new ObservableCollection<Actionresult>
下面的帖子效果很好,但是请参阅下面的评论。
如果Result
属性属于Files
集合中的数据对象,则如果您想在Result
属性返回false
时请禁用ListBoxItem
:
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsEnabled" Value="{Binding Path=Result}"/>
</Style>
</ListBox.ItemContainerStyle>