I'm trying to do the following: once my listview IsSelected
, I want to set my button's IsEnabled
property to true.
Here's what I've tried, but I'm getting the following exception:
'Initialization of 'System.Windows.Controls.ListView' threw an exception.' Line number '25' and line position '19'.
Here's the code:
<ListView ItemsSource="{Binding ReferenceCollection}" SelectedItem="{Binding SelectedReference}" Grid.ColumnSpan="2" Name="ListView1" >
<ListView.Triggers>
<Trigger Property="ListView.IsSelected" Value="True">
<Setter TargetName="okBtn" Property="Button.IsEnabled" Value="True" />
</Trigger>
</ListView.Triggers>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding ReferenceName}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
and Button:
<Button IsEnabled ="False" Grid.Row ="2" Content="OK" Name="okBtn" Click="addReference_Click" />
You can use DataTrigger in the Button:
<ListView Name="YourList">
<ListViewItem Content="1234" />
<ListViewItem Content="1234" />
<ListViewItem Content="1234" />
</ListView>
<Button Content="OK">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem, ElementName=YourList}"
Value="{x:Null}">
<Setter Property="IsEnabled"
Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With