I have a Listview with a textblock to populate a List, inside of the class is the property result, if my software is able to parse the file I style the textblock based on this property, but additional i would like to make this item not selectable.
Question:
How I bind the ItemcontainerStyle Property IsEnabled to the property of the collection?
I tried, but doesnt work:
<Setter Property="IsEnabled" Value="{Binding Path=ActionResult.Result ??? doesnt work }"/>
My current code:
<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>
Update: Model:
public class ActionResult
{
public string Name { get; set; }
public bool Result { get; set; }
public object Content { get; set; }
public string Exceptionmessage { get; set; }
}
Files is a Observablecollection of Type ActionResult
Files = new ObservableCollection<Actionresult>
The post below works well, but please see my comment below.