Trying to change DataContext of main window from usercontrol
On initialization of main window i set DataContext to usercontrol and on this usercontrol i have an event which suppose to change datacontext of main window to another usercontrol but nothing happens.
Here is xaml for main window:
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}" Width="auto" Height="auto" />
</Grid>
Here is C# for main window:
public MainWindow()
{
InitializeComponent();
DataContext = new LogInViewModel();
}
Here is xaml for LogInUserControl:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="250">
<StackPanel Width="125">
<TextBlock Text="Email:" Margin="5,0,5,0" Width="auto"/>
</StackPanel>
<StackPanel Width="125">
<TextBlock Text="Password:" Margin="5,0,0,0" Width="auto"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Margin="5,0,5,0" HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<PasswordBox Margin="0,0,0,5" HorizontalAlignment="Center" Height="23" VerticalAlignment="Top" Width="120"/>
</StackPanel>
<Button Content="Log In" Margin="0,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75"/>
</StackPanel>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="don't have account yet ?" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5"/>
<TextBlock Name="TBSignUp" Text="Sign Up" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5" PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown" PreviewMouseLeftButtonUp="TextBlock_PreviewMouseLeftButtonUp" Foreground="#FF0B36F5"/>
</StackPanel>
</Grid>
</Grid>
and here is C# for LogInUserControl:
public partial class LogInView : UserControl
{
string BlackForeground = "#FF000000" ;
string OriginalForeground = "#FF0B36F5";
public LogInView()
{
InitializeComponent();
}
private void TextBlock_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(OriginalForeground));
DataContext = new RegisterView();
}
private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(BlackForeground));
}
}
c# wpf xaml binding datacontext
add a comment |
On initialization of main window i set DataContext to usercontrol and on this usercontrol i have an event which suppose to change datacontext of main window to another usercontrol but nothing happens.
Here is xaml for main window:
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}" Width="auto" Height="auto" />
</Grid>
Here is C# for main window:
public MainWindow()
{
InitializeComponent();
DataContext = new LogInViewModel();
}
Here is xaml for LogInUserControl:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="250">
<StackPanel Width="125">
<TextBlock Text="Email:" Margin="5,0,5,0" Width="auto"/>
</StackPanel>
<StackPanel Width="125">
<TextBlock Text="Password:" Margin="5,0,0,0" Width="auto"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Margin="5,0,5,0" HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<PasswordBox Margin="0,0,0,5" HorizontalAlignment="Center" Height="23" VerticalAlignment="Top" Width="120"/>
</StackPanel>
<Button Content="Log In" Margin="0,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75"/>
</StackPanel>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="don't have account yet ?" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5"/>
<TextBlock Name="TBSignUp" Text="Sign Up" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5" PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown" PreviewMouseLeftButtonUp="TextBlock_PreviewMouseLeftButtonUp" Foreground="#FF0B36F5"/>
</StackPanel>
</Grid>
</Grid>
and here is C# for LogInUserControl:
public partial class LogInView : UserControl
{
string BlackForeground = "#FF000000" ;
string OriginalForeground = "#FF0B36F5";
public LogInView()
{
InitializeComponent();
}
private void TextBlock_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(OriginalForeground));
DataContext = new RegisterView();
}
private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(BlackForeground));
}
}
c# wpf xaml binding datacontext
2
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
1
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39
add a comment |
On initialization of main window i set DataContext to usercontrol and on this usercontrol i have an event which suppose to change datacontext of main window to another usercontrol but nothing happens.
Here is xaml for main window:
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}" Width="auto" Height="auto" />
</Grid>
Here is C# for main window:
public MainWindow()
{
InitializeComponent();
DataContext = new LogInViewModel();
}
Here is xaml for LogInUserControl:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="250">
<StackPanel Width="125">
<TextBlock Text="Email:" Margin="5,0,5,0" Width="auto"/>
</StackPanel>
<StackPanel Width="125">
<TextBlock Text="Password:" Margin="5,0,0,0" Width="auto"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Margin="5,0,5,0" HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<PasswordBox Margin="0,0,0,5" HorizontalAlignment="Center" Height="23" VerticalAlignment="Top" Width="120"/>
</StackPanel>
<Button Content="Log In" Margin="0,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75"/>
</StackPanel>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="don't have account yet ?" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5"/>
<TextBlock Name="TBSignUp" Text="Sign Up" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5" PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown" PreviewMouseLeftButtonUp="TextBlock_PreviewMouseLeftButtonUp" Foreground="#FF0B36F5"/>
</StackPanel>
</Grid>
</Grid>
and here is C# for LogInUserControl:
public partial class LogInView : UserControl
{
string BlackForeground = "#FF000000" ;
string OriginalForeground = "#FF0B36F5";
public LogInView()
{
InitializeComponent();
}
private void TextBlock_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(OriginalForeground));
DataContext = new RegisterView();
}
private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(BlackForeground));
}
}
c# wpf xaml binding datacontext
On initialization of main window i set DataContext to usercontrol and on this usercontrol i have an event which suppose to change datacontext of main window to another usercontrol but nothing happens.
Here is xaml for main window:
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}" Width="auto" Height="auto" />
</Grid>
Here is C# for main window:
public MainWindow()
{
InitializeComponent();
DataContext = new LogInViewModel();
}
Here is xaml for LogInUserControl:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="250">
<StackPanel Width="125">
<TextBlock Text="Email:" Margin="5,0,5,0" Width="auto"/>
</StackPanel>
<StackPanel Width="125">
<TextBlock Text="Password:" Margin="5,0,0,0" Width="auto"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Margin="5,0,5,0" HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<PasswordBox Margin="0,0,0,5" HorizontalAlignment="Center" Height="23" VerticalAlignment="Top" Width="120"/>
</StackPanel>
<Button Content="Log In" Margin="0,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75"/>
</StackPanel>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="don't have account yet ?" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5"/>
<TextBlock Name="TBSignUp" Text="Sign Up" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5" PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown" PreviewMouseLeftButtonUp="TextBlock_PreviewMouseLeftButtonUp" Foreground="#FF0B36F5"/>
</StackPanel>
</Grid>
</Grid>
and here is C# for LogInUserControl:
public partial class LogInView : UserControl
{
string BlackForeground = "#FF000000" ;
string OriginalForeground = "#FF0B36F5";
public LogInView()
{
InitializeComponent();
}
private void TextBlock_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(OriginalForeground));
DataContext = new RegisterView();
}
private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
TBSignUp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(BlackForeground));
}
}
c# wpf xaml binding datacontext
c# wpf xaml binding datacontext
asked Nov 13 '18 at 13:26
Igor BieńkowskiIgor Bieńkowski
115
115
2
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
1
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39
add a comment |
2
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
1
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39
2
2
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
1
1
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39
add a comment |
2 Answers
2
active
oldest
votes
In WPF you can get a shell window from anywhere:
Application.Current.MainWindow; // this is your shell window
Application.Current.MainWindow.DataContext; // this is your shell window data context
If you want to change the view of your user control or its data context, then I suggest doing it with the data context of the parent window.
If you want to change the interface, you can use Content Control as container by simply changing its Content property to all of your user controls.
As a result, each user control will have its own view and data context, and it will be independent of the other.
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
add a comment |
You need to set it on App.xaml.cs
.
App.xaml.cs:
public class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window=new MainWindow();
LogInViewModel vm=new LogInViewModel(); // You need to set DataContext...
window.DataContext=vm; // ...before showing up the window.
window.Show();
}
}
In the ViewModel patterns that I found from research, usage is before DataContext
, after Show();
.
I hope that solves your problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282061%2ftrying-to-change-datacontext-of-main-window-from-usercontrol%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In WPF you can get a shell window from anywhere:
Application.Current.MainWindow; // this is your shell window
Application.Current.MainWindow.DataContext; // this is your shell window data context
If you want to change the view of your user control or its data context, then I suggest doing it with the data context of the parent window.
If you want to change the interface, you can use Content Control as container by simply changing its Content property to all of your user controls.
As a result, each user control will have its own view and data context, and it will be independent of the other.
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
add a comment |
In WPF you can get a shell window from anywhere:
Application.Current.MainWindow; // this is your shell window
Application.Current.MainWindow.DataContext; // this is your shell window data context
If you want to change the view of your user control or its data context, then I suggest doing it with the data context of the parent window.
If you want to change the interface, you can use Content Control as container by simply changing its Content property to all of your user controls.
As a result, each user control will have its own view and data context, and it will be independent of the other.
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
add a comment |
In WPF you can get a shell window from anywhere:
Application.Current.MainWindow; // this is your shell window
Application.Current.MainWindow.DataContext; // this is your shell window data context
If you want to change the view of your user control or its data context, then I suggest doing it with the data context of the parent window.
If you want to change the interface, you can use Content Control as container by simply changing its Content property to all of your user controls.
As a result, each user control will have its own view and data context, and it will be independent of the other.
In WPF you can get a shell window from anywhere:
Application.Current.MainWindow; // this is your shell window
Application.Current.MainWindow.DataContext; // this is your shell window data context
If you want to change the view of your user control or its data context, then I suggest doing it with the data context of the parent window.
If you want to change the interface, you can use Content Control as container by simply changing its Content property to all of your user controls.
As a result, each user control will have its own view and data context, and it will be independent of the other.
answered Nov 13 '18 at 20:04
Mykhailo PantiaMykhailo Pantia
663
663
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
add a comment |
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
Thanks this is exactly what i was looking for :)
– Igor Bieńkowski
Nov 18 '18 at 0:22
add a comment |
You need to set it on App.xaml.cs
.
App.xaml.cs:
public class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window=new MainWindow();
LogInViewModel vm=new LogInViewModel(); // You need to set DataContext...
window.DataContext=vm; // ...before showing up the window.
window.Show();
}
}
In the ViewModel patterns that I found from research, usage is before DataContext
, after Show();
.
I hope that solves your problem.
add a comment |
You need to set it on App.xaml.cs
.
App.xaml.cs:
public class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window=new MainWindow();
LogInViewModel vm=new LogInViewModel(); // You need to set DataContext...
window.DataContext=vm; // ...before showing up the window.
window.Show();
}
}
In the ViewModel patterns that I found from research, usage is before DataContext
, after Show();
.
I hope that solves your problem.
add a comment |
You need to set it on App.xaml.cs
.
App.xaml.cs:
public class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window=new MainWindow();
LogInViewModel vm=new LogInViewModel(); // You need to set DataContext...
window.DataContext=vm; // ...before showing up the window.
window.Show();
}
}
In the ViewModel patterns that I found from research, usage is before DataContext
, after Show();
.
I hope that solves your problem.
You need to set it on App.xaml.cs
.
App.xaml.cs:
public class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window=new MainWindow();
LogInViewModel vm=new LogInViewModel(); // You need to set DataContext...
window.DataContext=vm; // ...before showing up the window.
window.Show();
}
}
In the ViewModel patterns that I found from research, usage is before DataContext
, after Show();
.
I hope that solves your problem.
answered Nov 13 '18 at 16:15
Burak YeniçeriBurak Yeniçeri
3310
3310
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282061%2ftrying-to-change-datacontext-of-main-window-from-usercontrol%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Both "change DataContext of main window from usercontrol" and "change datacontext of main window to another usercontrol" sounds horrible. Don't even think about it.
– Clemens
Nov 13 '18 at 13:31
do you have any other idea how to change views in wpf ? and can you explain why it sounds horrible ?
– Igor Bieńkowski
Nov 13 '18 at 13:33
1
Change views for example by assigning a value to the Content property of a ContentControl. A DataTemplate with an appropriate DataType would be chosen automatically, and the DataContext of the elements in the DataTemplate (e.g. a UserControl) would be set to the current Content. Start here: Data Templating Overview. Or take a look at Page Navigation.
– Clemens
Nov 13 '18 at 13:39