Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 5.68 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WPF Stretch ListBox Height 100% of Grid.Row?
  2. <Grid.ColumnDefinitions>
  3.         <ColumnDefinition Width=".24*"/>
  4.         <ColumnDefinition Width=".73*"/>
  5.     </Grid.ColumnDefinitions>
  6.     <Grid.RowDefinitions>
  7.         <RowDefinition Height=".9*"/>
  8.         <RowDefinition Height=".1*"/>
  9.     </Grid.RowDefinitions>
  10.     <ListBox Grid.Column="0" Grid.Row="0" Name="Subdivisions" SelectedItem="{Binding SelectedSubdivisionViewModel}" ItemsSource="{Binding Path=Subdivisions}" Grid.IsSharedSizeScope="True">
  11.         <ListBox.ItemTemplate>
  12.             <DataTemplate>
  13.                 <StackPanel>
  14.                     <Border BorderBrush="#FF4788c8" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8">
  15.                         <Expander IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}">
  16.                             <Expander.Header>
  17.                                 <StackPanel>
  18.                                     <Grid>
  19.                                         <Grid.ColumnDefinitions>
  20.                                             <ColumnDefinition Width="*" SharedSizeGroup="col1" />
  21.                                             <ColumnDefinition Width=".1*" SharedSizeGroup="col2" />
  22.                                             <ColumnDefinition Width="*" SharedSizeGroup="col3" />
  23.                                         </Grid.ColumnDefinitions>
  24.                                         <Grid.RowDefinitions>
  25.                                             <RowDefinition/>
  26.                                             <RowDefinition/>
  27.                                         </Grid.RowDefinitions>
  28.                                         <TextBlock Grid.Column="0" Grid.Row="0">
  29.                                             <TextBlock.Text>
  30.                                                 <MultiBinding StringFormat="Name: {0}">
  31.                                                   <Binding Path="SubdivisionName" />
  32.                                                   <Binding Path="SubdivisionID" />
  33.                                                 </MultiBinding>
  34.                                             </TextBlock.Text>
  35.                                         </TextBlock>
  36.                                         <TextBlock Grid.Column="2" Grid.Row="0">
  37.                                             <TextBlock.Text>
  38.                                                 <MultiBinding StringFormat="ID: {0}">
  39.                                                   <Binding Path="SubdivisionName" />
  40.                                                   <Binding Path="SubdivisionID" />
  41.                                                 </MultiBinding>
  42.                                             </TextBlock.Text>
  43.                                         </TextBlock>
  44.                                         <TextBlock Grid.Column="2" Grid.Row="1">
  45.                                             <TextBlock.Text>
  46.                                                 <MultiBinding StringFormat="ID: {0}">
  47.                                                   <Binding Path="SubdivisionName" />
  48.                                                   <Binding Path="SubdivisionID" />
  49.                                                 </MultiBinding>
  50.                                             </TextBlock.Text>
  51.                                         </TextBlock>
  52.                                     </Grid>
  53.                                 </StackPanel>
  54.                             </Expander.Header>
  55.                             <StackPanel>
  56.                                 <Grid>
  57.                                     <Grid.ColumnDefinitions>
  58.                                         <ColumnDefinition Width="*"/>
  59.                                         <ColumnDefinition/>
  60.                                         <ColumnDefinition/>
  61.                                     </Grid.ColumnDefinitions>
  62.                                     <Grid.RowDefinitions>
  63.                                         <RowDefinition />
  64.                                         <RowDefinition />
  65.                                     </Grid.RowDefinitions>
  66.                                     <TextBlock Text="{Binding ElementName=SubdivisionID}" />
  67.                                     <TextBlock Text="{Binding Path=SubdivisionID}" />
  68.                                 </Grid>
  69.                             </StackPanel>
  70.                         </Expander>
  71.                     </Border>
  72.                 </StackPanel>
  73.             </DataTemplate>
  74.         </ListBox.ItemTemplate>
  75.     </ListBox>
  76.        
  77. <Grid x:Name="LayoutRoot" Background="LightGray">
  78.     <Grid.ColumnDefinitions>
  79.         <ColumnDefinition Width=".24*"/>
  80.         <ColumnDefinition Width=".73*"/>
  81.     </Grid.ColumnDefinitions>
  82.     <Grid.RowDefinitions>
  83.         <RowDefinition Height=".9*"/>
  84.         <RowDefinition Height=".1*"/>
  85.     </Grid.RowDefinitions>
  86.     <ListBox Name="Subdivisions" SelectedItem="{Binding SelectedSubdivisionViewModel}" ItemsSource="{Binding Path=Subdivisions}" Grid.IsSharedSizeScope="True" Height="{Binding ElementName=LayoutRoot, Path=ActualHeight}" >
  87.        
  88. <Grid Background="Red">
  89.  
  90.     <Grid.ColumnDefinitions>
  91.         <ColumnDefinition Width=".24*"/>
  92.         <ColumnDefinition Width=".73*"/>
  93.     </Grid.ColumnDefinitions>
  94.     <Grid.RowDefinitions>
  95.         <RowDefinition Height=".9*"/>
  96.         <RowDefinition Height=".1*"/>
  97.     </Grid.RowDefinitions>
  98.  
  99.     <ListBox Background="LightGray"
  100.              ItemsSource="{x:Static Fonts.SystemFontFamilies}"/>
  101.  
  102.     <ListBox Grid.Column="1" Grid.Row="0" Background="LightSlateGray">
  103.         <ListBoxItem>John</ListBoxItem>
  104.         <ListBoxItem>Jane</ListBoxItem>
  105.         <ListBoxItem>Fido</ListBoxItem>
  106.     </ListBox>
  107.  
  108.     <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="Tomato" />
  109.  
  110. </Grid>