committed

This commit is contained in:
HuskyTeufel
2021-05-05 13:06:56 +02:00
parent 2c4bcde9c8
commit af01e537cf
17 changed files with 234 additions and 38 deletions

View File

@@ -13,5 +13,6 @@ namespace GuiWPF
/// </summary>
public partial class App : Application
{
}
}

75
GuiWPF/DelegateCommand.cs Normal file
View File

@@ -0,0 +1,75 @@
using System;
using System.Windows.Input;
namespace GuiWPF {
public class DelegateCommand : ICommand {
/// <summary>
/// Action to be performed when this command is executed
/// </summary>
private Action<object> executionAction;
/// <summary>
/// Predicate to determine if the command is valid for execution
/// </summary>
private Predicate<object> canExecutePredicate;
/// <summary>
/// Initializes a new instance of the DelegateCommand class.
/// The command will always be valid for execution.
/// </summary>
/// <param name="execute">The delegate to call on execution</param>
public DelegateCommand(Action<object> execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the DelegateCommand class.
/// </summary>
/// <param name="execute">The delegate to call on execution</param>
/// <param name="canExecute">The predicate to determine if command is valid for execution</param>
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
{
throw new ArgumentNullException("execute");
}
this.executionAction = execute;
this.canExecutePredicate = canExecute;
}
/// <summary>
/// Raised when CanExecute is changed
/// </summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Executes the delegate backing this DelegateCommand
/// </summary>
/// <param name="parameter">parameter to pass to predicate</param>
/// <returns>True if command is valid for execution</returns>
public bool CanExecute(object parameter)
{
return this.canExecutePredicate == null ? true : this.canExecutePredicate(parameter);
}
/// <summary>
/// Executes the delegate backing this DelegateCommand
/// </summary>
/// <param name="parameter">parameter to pass to delegate</param>
/// <exception cref="InvalidOperationException">Thrown if CanExecute returns false</exception>
public void Execute(object parameter)
{
if (!this.CanExecute(parameter))
{
throw new InvalidOperationException("The command is not valid for execution, check the CanExecute method before attempting to execute.");
}
this.executionAction(parameter);
}
}
}

5
GuiWPF/HomePage.cs Normal file
View File

@@ -0,0 +1,5 @@
namespace GuiWPF {
public class HomePage {
public string PageTitle {get;set;}
}
}

12
GuiWPF/HomePageView.xaml Normal file
View File

@@ -0,0 +1,12 @@
<UserControl x:Class="GuiWPF.HomePageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Content="lool"></Button>
<TextBlock FontSize="20" Text="Lala" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace GuiWPF
{
public class HomePageViewModel : ViewModelBase {
//public string PageTitle = "HomePage";
public HomePage Model {get; private set;}
public HomePageViewModel(HomePage model) {
this.Model = model;
}
public string PageTitle {
get {
return Model.PageTitle;
}
set {
Model.PageTitle = value;
OnPropertyChanged();
}
}
}
}

45
GuiWPF/MainViewModel.cs Normal file
View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Input;
namespace GuiWPF
{
public class MainViewModel : ViewModelBase
{
public string PageTitle { get; set; }
public ICommand LoadHomePageCommand {get; private set;}
public ICommand LoadSettingsPageCommand {get; private set;}
private ViewModelBase _currentViewModel;
public ViewModelBase CurrentViewModel {
get {
Trace.WriteLine("CurrentAbgefragt");
return _currentViewModel;
}
set {
Trace.WriteLine("CurrentView ist geändert worden");
_currentViewModel = value;
OnPropertyChanged();
}
}
public MainViewModel()
{
PageTitle = "Dichtheitsprüfung by Damian";
LoadHomePage();
LoadHomePageCommand = new DelegateCommand(o => this.LoadHomePage());
LoadSettingsPageCommand = new DelegateCommand(o => this.LoadSettingsPage());
//Initialisieren();
}
private void LoadHomePage() {
CurrentViewModel = new HomePageViewModel(new HomePage() { PageTitle = "Home"});
}
private void LoadSettingsPage() {
CurrentViewModel = new SettingsPageViewModel();
}
}
}

View File

@@ -5,14 +5,20 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GuiWPF"
mc:Ignorable="d"
Title="{Binding Titel, StringFormat={} DP - {0}}" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="WWWings-Flugbuchung" FontSize="30" Margin="5"/>
<ContentControl Content="{Binding}" Grid.Row="1"/>
</Grid>
Title="{Binding PageTitle, StringFormat={} DP - {0}}" Height="450" Width="800">
<Window.Resources>
<DataTemplate DataType="{x:Type local:HomePageViewModel}">
<local:HomePageView />
</DataTemplate>
<DataTemplate DataType="{x:Type local:SettingsPageViewModel}">
<local:SettingsPageView />
</DataTemplate>
</Window.Resources>
<DockPanel>
<StackPanel DockPanel.Dock="Left">
<Button Content="Home Page" Command="{Binding Path=LoadHomePageCommand}" />
<Button Content="Settings Page" Command="{Binding Path=LoadSettingsPageCommand}"/>
</StackPanel>
<ContentControl Content="{Binding CurrentViewModel}" Name="Contenter"></ContentControl>
</DockPanel>
</Window>

View File

@@ -1,5 +1,4 @@
using GuiWPF_ViewModel;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -23,8 +22,8 @@ namespace GuiWPF
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
//InitializeComponent();
//this.DataContext = new MainViewModel();
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace GuiWPF
{
public class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName="")
{
if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Trace.WriteLine(string.Format("OnPropertyChanged {0}",propertyName));
}
}
}
}

View File

@@ -0,0 +1,11 @@
<UserControl x:Class="GuiWPF.SettingsPageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock FontSize="20" Text="{Binding Path=PageTitle}" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GuiWPF
{
public class SettingsPageViewModel : ViewModelBase {
public string PageTitle = "SettingsPage";
}
}

37
GuiWPF/ViewModelBase.cs Normal file
View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GuiWPF
{
public class ViewModelBase : NotificationObject
{
private bool valIsBusy;
private string valBusyMessage;
public bool IsBusy
{
get => valIsBusy;
set
{
if(valIsBusy != value)
{
valIsBusy = value;
OnPropertyChanged();
}
}
}
public string BusyMessage
{
get => valBusyMessage;
set
{
if(valBusyMessage != value)
{
valBusyMessage = value;
OnPropertyChanged();
}
}
}
}
}