blend wpf: element page using inside element windows
-
Friday, December 21, 2012 6:19 PM
Hi all,
i've a window_page.xaml (main page) and I want to put inside it some page.xaml (page1, page2 etc..) changing on eveytime i click some button onto window_page.xaml.
It is possible?
It's like a web dynamic webSite: i've homePage and depend on click change the page on the center.
How can I do that?
I'm trying over and over and i Think it's something like these
http://wpf.2000things.com/2012/07/27/612-application-event-sequence-for-page-based-applications/
http://wpf.2000things.com/2010/07/26/14-page-based-navigation/
All Replies
-
Saturday, December 22, 2012 2:48 AMModeratorYou could use a UserControl based class and create instances of that.
-
Wednesday, December 26, 2012 12:27 AMmaybe do you have any examples for that?
i looked for around web but nothing of similar i found.
Everything i found out it was about userControls meant like object onto page (kinda button for example) -
Wednesday, December 26, 2012 1:15 AMModeratorCould you be more specific about what you are trying to do?
-
Thursday, December 27, 2012 12:10 AM
something like this
where "content" must change depens on button is pressed.
In VS i had done: if you press button 1, hide everything from content and show me the controls concern button1; if you press button 2 hide everything from content and show me the controls concern button2.
Do u catch my goal?
-
Thursday, December 27, 2012 1:17 AM
However, I've tried to do it through this steps:
1. set up window.xaml with two buttons
2. i've made a simple UserControl1: it's a textbox
3. in window.xaml.cs i wrote a referiment to UserControl1 (and it should appear) after clicked on button1
UserControl1 var = new UserControl1(); private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { // TODO: aggiungere l'implementazione del gestore dell'evento in questa posizione. var.Show(); }4. in window.xaml I added this line
xmlns:ctrl="clrnamespace:UserControl1;assembly=UserControl1"
When I try to launch the project doesn't work.. it's says this error(something like that i traslated):
name_project.UserControl1 doesn't have a definition of 'Show()'
and doesn't exists any extension of this method. Probably misses a directive using or assembly reference for that.
-
Thursday, December 27, 2012 2:26 AMModeratorYou could set the visibility of the controls you want to show/hide in the button handlers. The property is Visiblity and the values are Visible or Collapsed.
-
Thursday, December 27, 2012 11:18 AM
So, without using any UserControls?
Just putting the controls i need on the same window and playing with visibility?
So, like i had done in VS before. Right?
But I thought If I did it using userControls specific for each eventClick button it would be better. No?
Besides I'd like to do the content different in each own file because i can arrange things better than work-arrange in the same window and playing with visibily. Infact when i was working on VS (to do 'something like that' above mentioned), I had projected every control onto same window and it was so confusing.. so this time, I thought using blend things are coming better given that it's a tool for design and management other things in cool way.- Edited by ludowanderlust Thursday, December 27, 2012 12:56 PM
- Edited by ludowanderlust Thursday, December 27, 2012 12:58 PM
-
Friday, December 28, 2012 3:32 PMModeratorThat is one of the main uses for UserControls, to separate content into reusable pieces, and keep them in their own context. You can separate them into separate UserControls, and still control their visibility to show/hide them.
-
Friday, December 28, 2012 3:41 PMYeah... and maybe do u have some tutorials for that?
-
Sunday, December 30, 2012 5:10 PM
Hi,
finally thank to Abhishek Sur
i solved my problem, here you are his good explanation
What you have to do is to create a new instance of your User control. Create a UserControl into your solution. Create an UI with a Grid which will place the Buttons and on the right hand side, place a ContentControl. For instance <Grid> <Grid.ColumnDefination> <ColumnDefination /> <ColumnDefination /> </Grid.ColumnDefination> <StackPanel Orientation="Vertical" Grid.Column="0"> <Button Content="Button1" OnClick="LoadUserControl1"/> <Button Content="Button2" OnClick="LoadUserControl2"/> </StackPanel> <ContentControl x:Name="contentHost" Grid.Column="1" /> </Grid> Now when LoadUserControl1 is clicked, you want to create an object of UserControl1 and put it in Contentcontrol. For Instance, public void LoadUserControl1(...) { var u1 = new UserControl1(); this.contentHost.Content = u1; } similarly you can do with content 2. You can read my WPF tutorials from here for better understanding http://www.abhisheksur.com/2010/12/wpf-tutorial.html
Hoping it will help someone.
- Edited by ludowanderlust Sunday, December 30, 2012 5:10 PM

