1

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.

Shazter
  • 305
  • 1
  • 4
  • 17
  • What's the type of the Files collection and where is the ActionResult property defined? What's its type? – mm8 Mar 10 '17 at 11:32

1 Answers1

1

If the Result property belongs to the data object in the Files collection this should work if you want to disable the ListBoxItem when the Result property returns false:

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="IsEnabled" Value="{Binding Path=Result}"/>
    </Style>
</ListBox.ItemContainerStyle>
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Works well,after compile and test, but if i enter the path=Result, then the xaml code window claims the property of path "Cannot resolve property 'Result' in datacontext of type .... (myviewmodelnamespace". The ActionResult data object model is located in a different assembly, but i mentioned this xmlns:model="clr-namespace:XMLManager.Model;assembly=XMLManager" and the datacontext is set with viewmodellocator DataContext="{Binding Report, Source={StaticResource Locator}. Does somebody could kindly explain why is claimed in code? Is now the second time that i encounter this issue. – Shazter Mar 10 '17 at 12:21
  • http://stackoverflow.com/questions/25549826/resharper-wpf-error-cannot-resolve-symbol-myvariable-due-to-unknown-datacont I will try this solutions for my problem – Shazter Mar 10 '17 at 12:30