tags:

views:

123

answers:

1

Currently I have a toggle button that is bound to a boolean property (DualLayout) in my code behind. When the boolean is set to True, then I want my second row in my grid (and grid splitter) to hide and have the first row take up the entire space of the grid. Once the boolean is set to False, I want the grid splitter and bottom row to appear.

Here is a snippet of my xaml

<ToggleButton Name="toggleLayout" Margin="66,1,0,1" Width="25" HorizontalAlignment="Left" IsChecked="{Binding DualLayout}" Checked="toggleLayout_Clicked" Unchecked="toggleLayout_Clicked">
            <ToggleButton.Style>
                <Style TargetType="{x:Type ToggleButton}">
                    <Style.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate DataType="{x:Type ToggleButton}">
                                        <Image Source="Images/PlayHS.png"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="ToolTip" Value="Receive and Transmit Windows Split."/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="false">
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate DataType="{x:Type ToggleButton}">
                                        <Image Source="Images/PauseHS.png"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="ToolTip" Value="Receive and Transmit Windows Combined."/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ToggleButton.Style>
        </ToggleButton>
    <Grid x:Name="transmissionsGrid" Margin="0,28,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" MinHeight="100" />
        </Grid.RowDefinitions>
        <transmission:TransmissionsControl x:Name="transmissionsReceive" TransmissionType="Receive" Margin="0,0,0,5" />
        <GridSplitter Name="gridSplitter1" Grid.Row="0" Background="White" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Foreground="Firebrick"  />
        <transmission:TransmissionsControl x:Name="transmissionsTransmit" TransmissionType="Transmit" Grid.Row="1"  />
    </Grid>
+1  A: 

This is untested, but I believe it should work.

First, if you want your first row to take up the whole space, you'll want to define your RowDefinitions as

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto" />  <!-- Edit: Removed MinHeight="100" -->
</Grid.RowDefinitions>

For showing/hiding the controls, you'll need to bind their Visibility property either to your DualLayout property (if the class properly implements INotifyPropertyChanged), or (perhaps more simply) to the IsChecked property of the ToggleButton.

For instance (the same applies to the GridSplitter):

<!-- EDIT: Added MinHeight="100" here instead -->
<transmission:TransmissionsControl x:Name="transmissionsTransmit"
               TransmissionType="Transmit" 
               Grid.Row="1"
               MinHeight="100"
               Visibility={Binding ElementName=toggleLayout,
                                   Path=IsChecked,
                                   Converter={StaticResource boolToVis}}"  />

At some level above the controls in question (here I am doing it at the window level) you need to add built-in BooleanToVisibilityConverter resource:

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="boolToVis" />
</Window.Resources>
Wonko the Sane
It hide the controls (GridSplitter and Bottom Control), but the top control does not fill up the entire space anymore. It just stays the same height
Travyguy9
You need to set the VerticalAlignment of your Grid to Stretch. Right now, the Grid doesn't know to fill all the available space. Note that you may want to set the HorizontalAlignment to Stretch as well if you want it to fill the horizontal space.I assume that you also made the change to the RowDefinitions that I specified above as well.Hope this helps!
Wonko the Sane
Sorry this didn't help. It still acts the same way. Did I miss something? Here is what I got (minus the Toggle button). It may be hard to read through this though...sorryI also needed to break it up so I could paste it..
Travyguy9
<Grid x:Name="transmissionsGrid" Margin="0,28,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto" MinHeight="100"/> </Grid.RowDefinitions>
Travyguy9
<transmission:TransmissionsControl x:Name="transmissionsReceive" TransmissionType="Receive" Margin="0,0,0,5" /><GridSplitter Name="gridSplitter1" Grid.Row="0" Background="White" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Foreground="Firebrick" Visibility="{Binding ElementName=toggleLayout, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" />
Travyguy9
<transmission:TransmissionsControl x:Name="transmissionsTransmit" TransmissionType="Transmit" Grid.Row="1" Visibility="{Binding ElementName=toggleLayout, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" /> </Grid>
Travyguy9
You need to get rid of the MinHeight attribute in the second row of your grid. That is forcing that row to always be at least 100 units tall.If you want your second TransmissionControl to be a minimum of 100, you can add that MinHeight attribute in the TransmissionControl itself, rather than on the row. In other words, you want the control to be 100 tall (when Visible), not the row (the row will automatically size to the control).
Wonko the Sane
Note: I've made the changes in the answer above.
Wonko the Sane