I am trying to create a main window with buttons on the right and when a button is clicked a different user control screen should show on the left side. When creating the main XAML , what can be used as a container for the user controls to display in?
Asked
Active
Viewed 304 times
0
-
2Any Panel, e.g. a Grid, or a Border or a ContentControl. You could declare multiple DataTemplates with different DataTypes, that contain your UserControls. By assigning an object of a certain type to the Content property of a ContentControl, the DataTemplate with the appropriate DataType would be selected automatically, and the UserControl that it contains would automatically be instantiated. The DataTemplate would declare Bindings of the UserControl's properties to those of the data (or view model) type. – Clemens Jul 28 '18 at 21:15
-
2See [Data Templating Overview](https://learn.microsoft.com/en-us/dotnet/framework/wpf/data/data-templating-overview). – Clemens Jul 28 '18 at 21:21
-
I created a TabControl in my Grid to display a user control when app starts,but my mainwindow class does not see my usercontrol class to add it to the container.How do I add it to my container in mainwindow class? All my different UserControls should display in the same container on button clicks. – user8466504 Jul 30 '18 at 09:07
-
they should just show up in toolbox if part of current solution. Can you show us what you've tried so far? – Jeff R. Jul 30 '18 at 16:51
-
https://stackoverflow.com/questions/18523745/wpf-dynamic-view-content – kenny Aug 01 '18 at 14:21
-
The problem now is that my usercontrol should save data to SQLite Database, but now on my buttons click event thats on my usercontrol crashes my program "Program in break mode". and it crashes with only this line in the event SQLiteConnection con = new SQLiteConnection(conString); When I remove this and put a MessageBox , It displays the MessageBox and does not crash?? – user8466504 Aug 01 '18 at 14:29
1 Answers
1
I Used a TabControl in a ScrollViewer as the container in a column of the Grid.
<ScrollViewer Grid.Column="1">
<TabControl x:Name="Container" >
</TabControl>
</ScrollViewer>
This was the code I needed to change on button click:
Container.Items.Clear();
var login = new UserRegisterUserControl();
Container.Items.Add(login);
Container.Items.Refresh();

user8466504
- 69
- 2
- 11