tags:

views:

68

answers:

1

Below is a fine piece of artwork that represents a WPF form with a listbox on the left and a content control on the right. I would like to set it so if the list box is empty, then the content control is invisible. What property/event should I hook to?

----- -----
| a | | c |
| b | |   |
----- -----
+2  A: 

You should create a Style for the the ContentControl, and use a Trigger to determine when the List has 0 items, like so:

<ListBox x:Name="uiList">...</ListBox>
<ContentControl>
  <ContentControl.Content>
   <TextBox Text="List has items." />
  </ContentControl.Content>
  <ContentControl.Style>
   <Style TargetType="{x:Type ContentControl}">
    <Style.Triggers>
     <DataTrigger Binding="{Binding ElementName=uiList, Path=Items.Count}"
         Value="0">
      <Setter Property="Visibility"
        Value="Collapsed" />
     </DataTrigger>
    </Style.Triggers>
   </Style>
  </ContentControl.Style>
 </ContentControl>
rmoore
That worked perfectly, thanks!
Jake Pearson