Click here to Skip to main content
11,647,748 members (67,064 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF wpftoolkit
In My WPF Aplication, Here is one example, I am having One mainwindow and two UserControls named One And Two. In my Main window XAML code like,
<Window x:Class="WpfApplication9.MainWindow"
        Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication9">
        <my:One HorizontalAlignment="Left" Margin="266,88,0,0" x:Name="one1" VerticalAlignment="Top" />
        <my:Two HorizontalAlignment="Left" Margin="254,216,0,0" x:Name="two1" VerticalAlignment="Top" Visibility="Hidden"/>
At the same time Usercontrol--One.xaml code contains
<UserControl x:Class="WpfApplication9.One"
             d:DesignHeight="140" d:DesignWidth="188">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="53,53,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" FontFamily="TeX Gyre Adventor" FontWeight="Bold" />
My requirement is when the user clicks on the button1 we need to show the usercontrol two on the main window. kindly tell me is this possible, if possible which way should i proceed.
Posted 14-Feb-13 0:45am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi it's very's not suitable raiseEvent in userControls. you can do this.your mainWindow.xaml must be like following:
<my:one x:name="OneUserControl""Show" />
<my:two x:name="TwoUserControl" visibility="Hidden" />
your mainWindow.cs must be like : private void Show(object sender,RoutedEventArgs e) { Button button=e.OriginalSource as Button; if(button==null) { return ; } else { TwoUserControl.Visibility=Visibility.Visible; } } GoodLuck
D-Kishore at 6-Mar-13 0:30am
Yes its fine, but In my application TwoUserControl is dependent on the OneUserControl. When I use above code at the same time two controls are loading. Once the user clicks on the button from OneUserControl then only TwoUserControl should load. can you have any idea about this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 500
1 F-ES Sitecore 410
2 OriginalGriff 322
3 DamithSL 315
4 CPallini 290
0 OriginalGriff 1,342
1 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 795

Advertise | Privacy | Mobile
Web03 | 2.8.150804.3 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100