tags:

views:

318

answers:

2

How can I set expander to show some content it encloses even in collapsed state ? I have the following code snippet, can anyone point changes to this code ?

<Window x:Class="UI2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="358" Width="300">
<TabControl>
    <TabItem Header="Buga Buga">
        <StackPanel>
            <Expander ClipToBounds="False">
                <ListBox Name="lstProcesses"
                         MinHeight="60">
                </ListBox>
            </Expander>
        </StackPanel>
    </TabItem>
</TabControl>

Thanks

+1  A: 

It doesn't sound like Expander is the control you should be using for this scenario. Expander has a header, and content, like this:

<Expander Header="Visible all the time">
    <TextBlock Text="Hidden until expanded" />
</Expander>

It sounds to me like you want a control that's set to a specific height some of the time, and unrestrained at other times.

I think you could achieve this by binding a ToggleButton (which Expander uses too, internally) to the MaxHeight property of your ListBox.

Try something like this in Kaxaml:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:diag="clr-namespace:System.Diagnostics;assembly=System">

  <Page.Resources>
    <!-- A way of getting some test data in Kaxaml -->
    <ObjectDataProvider x:Key="Processes"
                        MethodName="GetProcesses"
                        ObjectType="{x:Type diag:Process}" />
  </Page.Resources>

  <StackPanel>
    <ToggleButton Name="Expand" Content="Expand" />
    <ListBox Name="lstProcesses" 
             ItemsSource="{Binding Source={StaticResource Processes}}"
             DisplayMemberPath="ProcessName">
      <ListBox.Style>
        <Style TargetType="ListBox">
          <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=Expand, Path=IsChecked}"
                         Value="False">
              <Setter Property="MaxHeight" Value="60" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </ListBox.Style>
    </ListBox>
  </StackPanel>
</Page>
Drew Noakes
A: 

Here's a quick example of how to the Collapsed text (the Header) to the selected item in the listbox contained within the expander:

<Expander ClipToBounds="False">
    <ListBox Name="lstProcesses"
                 MinHeight="60">
    </ListBox>
    <Expander.Header>
        <TextBlock Text="{Binding SelectedItem, ElementName=lstProcesses}"/>
    </Expander.Header>
</Expander>
Mark Synowiec