Wpf page change problem

Dec 31 2018 9:30 AM
Hello,
 
I am a beginner and I want to create an application with WPF (xaml and c #), so my problem is the page change. I go through a "ContentControl" which is on my mainwindows by changing the "Content" by a usercontrol window. When I call a method from a button that is on the mainwindows the page change is done but when I ask from a file usercontrol it does not work when I call the same method or is the problem? I already tried with a frame and same problem.
 
mainwindows.xaml
 
<Grid>
<DockPanel>
<ContentControl x:Name="Content" />
</DockPanel>
<Button Content="Button" HorizontalAlignment="Left" Margin="73,43,0,0" VerticalAlignment="Top" Width="75" Click="Logon_Click"/>
</Grid>
 
mainwindows.xaml.cs
 
private void Logon_Click(object sender, RoutedEventArgs e)
{
this.Changement<index>();
}
public void Changement<T>() where T : new()
{
Content.Content = new T();
}
 
When launching my application I click on the button to display the file index.xaml on my page and when I click on a button of the index page to call the method "Changement()" and change the Content by usercontrol and it does not change not the page. But if I change the index parameter when opening the application by any other file it works but since my usercontrol impossible. yet all the methods work well just the page that does not change.
 
Index.xaml.cs
 
public partial class index : UserControl
{
Mainwindows Main = new Mainwindows();
main.Changement<creation>();
}

Answers (2)