Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Toggle two views (Windows) in MVVM WPF
- /// <summary>
- /// Application_Startup
- /// </summary>
- /// <param name = "sender"></param>
- /// <param name = "e"></param>
- private void Application_Startup(object sender, StartupEventArgs e)
- {
- log.Debug("Application_Startup " + Utility.FUNCTION_ENTERED_LOG);
- try
- {
- if (e.Args.Length == 0)
- {
- AboutDialog.SpashScreen(Utility.TOOL_NAME,
- Utility.TOOL_VERSION);
- MainView mainForm = new MainView();
- mainForm.ShowDialog();
- }
- else
- {
- string key = null;
- foreach (string arg in e.Args)
- {
- if (arg.StartsWith("-"))
- {
- //this is a key
- key = arg;
- if (key.Equals("-config"))
- {
- CommandLineArgs.Add(key, "config");
- break;
- }
- if (key.Equals("-start"))
- {
- CommandLineArgs.Add(key, "start");
- }
- }
- else
- {
- //should be a value
- if (key == null)
- {
- throw new Exception(
- "The command line arguments are malformed.");
- }
- CommandLineArgs.Add(key, arg);
- key = null;
- }
- }
- string config = string.Empty;
- foreach (object k in App.CommandLineArgs.Keys)
- {
- config += CommandLineArgs[k].ToString();
- }
- switch (config)
- {
- case "config":
- AboutDialog.SpashScreen(
- Utility.TOOL_NAME,
- Utility.TOOL_VERSION);
- MainView mainForm = new MainView();
- mainForm.ShowDialog();
- break;
- case "start" :
- ExecutionForm execuForm= new ExecutionForm();
- execuForm.ShowDialog();
- break;
- default:
- MessageBox.Show("Incorrect Parameters",
- Utility.TOOL_NAME);
- Application.Current.Shutdown();
- break;
- }
- }
- log.Debug("Application_Startup" + Utility.FUNCTION_EXIT_LOG);
- }
- catch (Exception ex)
- {
- log.Error("Application_Startup" + ex.Message, ex);
- }
- }
- <DockPanel LastChildFill="true">
- <Menu DockPanel.Dock="Top" ...>
- </Menu>
- <ContentControl Content="{Binding}" ... />
- </DockPanel>
- <Window.Resources>
- <DataTemplate x:Key="ConfigView" ... />
- <DataTemplate x:Key="ExecutionView" ... />
- </Window.Resources>
- public class ViewModel : INotifPropertyChanged
- {
- private string mode;
- public string Mode
- {
- get { return mode; }
- set { mode = value; NotifPropertyChanged("Mode"); }
- }
- private IComamnd changeModeCommand;
- public ICommand ChangeModeCommand
- {
- get
- {
- if (changeModeCommand == null)
- changeModeCommand
- = new DelegateCommand(
- OnModeChange,
- CanModeChange);
- return changeModeCommand;
- }
- }
- //// Other properties and functions go here ...
- }
- <Window.InputBindings>
- <KeyBinding Command="{Binding ChangeModeCommand}"
- Key="F12" />
- </Window.InputBindings>
- <ContentControl Content="{Binding}">
- <ContentControl.Style>
- <Style TargetType="{x:Type ContentControl}">
- <Style.Triggers>
- <DataTrigger Binding="{Binding Mode}" Value="Config">
- <Setter Property="ContentTemplate"
- Value="{StaticResource ConfigView}"/>
- </DataTrigger>
- <DataTrigger Binding="{Binding Mode}" Value="Execution">
- <Setter Property="ContentTemplate"
- Value="{StaticResource ExecutionView}"/>
- </DataTrigger>
- </Style.Triggers>
- </Style>
- </ContentControl.Style>
- </ContentControl>
Add Comment
Please, Sign In to add comment