forum

Home / DeveloperSection / Forums / Button handlers in XAML

Button handlers in XAML

marcel ethan196616-Aug-2013
Hi Mindstick!

I have simple WPF layout task and looking to avoid code-behind if possible.

I have two panels left and right. When I am colapsing left panel - right panel gets stretched ... this is my xaml:

        <Grid Name="gridContainer">

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="Auto"/>

                <ColumnDefinition Width="5"/>

                <ColumnDefinition Width="*"/>

            </Grid.ColumnDefinitions>

            <StackPanel Background="Aqua" Grid.Column="0" Name="leftPanel" >

                <TextBlock FontSize="35" Foreground="#58290A" TextWrapping="Wrap">Left Hand Side</TextBlock>

            </StackPanel>

            <GridSplitter Name="leftSplitter" Grid.Column="1" HorizontalAlignment="Stretch"/>

            <StackPanel Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

                <Label Content="... Clien Area .. Has to Stretch vertically and horizontally" Margin="10"></Label>

                <Button Click="LeftButton_Click" Margin="10">Close Left Panel</Button>                    

            </StackPanel>

        </Grid>

This is code-behind:

    private void LeftButton_Click(object sender, RoutedEventArgs e)

    {

        if(leftPanel.Visibility == System.Windows.Visibility.Visible)

        {

            gridContainer.ColumnDefinitions[0].Width = GridLength.Auto;

            leftPanel.Visibility = System.Windows.Visibility.Collapsed;

            leftSplitter.Visibility = System.Windows.Visibility.Collapsed;

        }

        else

        {

            gridContainer.ColumnDefinitions[0].Width = GridLength.Auto;

            leftPanel.Visibility = System.Windows.Visibility.Visible;

            leftSplitter.Visibility = System.Windows.Visibility.Visible;

        }

    }

I am wondering, are there any way to avoid the code behind here? and acomplish this task in XAML only?

Thanks for advice



Updated on 17-Aug-2013

Can you answer this question?


Answer

1 Answers

Liked By