Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Expand/Close Expander control in parent UserControl or Window

$
0
0

Hi, using C# 2010 Express WPF form
I have MainWindow with expander control and also calls EnvUsercontrol
EnvUserControl itself has an Expander control and also calls JobUserControl

Now, inside JobUserControl on clicking a button 'Action',
I want to Expand/Close the Expander controls in EnvUserControl and MainWindow
The button click event itself shouldn't be tied to this.
After the button is clicked, based on certain conditions I want to set isExpanded property of the Expander control in the parent EnvUserControl and MainWindow

A working solution would be great !

Below is the code of the MainWindow and 2 Usercontrols

MainWindow.xaml

<Window x:Class="WpfAppExpander.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfAppExpander"
        Title="MainWindow" Height="350" Width="525"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition><RowDefinition Height="Auto"></RowDefinition></Grid.RowDefinitions><Expander Name="MainExpander" Header="MainExpander" Grid.Row="0"><Label>Inside Main Expander</Label></Expander><TabControl Grid.Row="1"><TabItem Header="ENV1"><local:EnvUserControl></local:EnvUserControl></TabItem></TabControl></Grid></Window>

EnvUserControl.xaml

<UserControl x:Class="WpfAppExpander.EnvUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfAppExpander"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition><RowDefinition Height="Auto"></RowDefinition></Grid.RowDefinitions><Expander Name="EnvExpander" Header="EnvExpander" Grid.Row="0"><Label>Inside Env Expander</Label></Expander><TabControl Grid.Row="1"><TabItem Header="Job1"><local:JobUserControl></local:JobUserControl></TabItem></TabControl></Grid></UserControl>


JobUserControl.xaml

<UserControl x:Class="WpfAppExpander.JobUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"></RowDefinition><RowDefinition Height="Auto"></RowDefinition></Grid.RowDefinitions><Button Name="btnAction" Content="Action" Grid.Row="0" Click="btnAction_Click"></Button></Grid></UserControl>

Thanks,

-srinivas y.


sri


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>