This question is in reference to this link Opening new window in MVVM WPF.
If I have the following:
public class WindowService:IWindowService {
public void ShowWindow(object viewModel){
var win = new Window {Content = viewModel};
win.Show();
}
}
and my app.xaml code:
<DataTemplate DataType="{x:Type local:MyViewModel}">
<local:MyUserControlView />
</DataTemplate>
I don't want to add style in the code as follow:
public class WindowService:IWindowService {
public void ShowWindow(object viewModel){
var win = new Window {Content = viewModel};
win.SizeToContent = SizeToContent.WidthAndHeight;
win.ResizeMode = ResizeMode.NoResize;
win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
win.Icon =...
win.Show();
}
}
Is there a way to do this in the Xaml with the dataTemplate?
I want a way to be able to change the style of the window created in WindowService in xaml not in the code. Not a global style but if for example I have viewModel1 and viewModel2 showWindow will be able to create two windows with different styles according to the viewModel passed to it