Created
October 3, 2019 10:29
-
-
Save McTopaz/4ebdffa8281c772dc93cc73d1b5fe1f5 to your computer and use it in GitHub Desktop.
Struktur av MVVM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace My_WPF_Project | |
{ | |
public class Controller | |
{ | |
vmHeader Vm { get; set; } | |
public Controller(vmHeader vm) | |
{ | |
Vm = vm; | |
Vm.Save.CallBack = Save(); | |
Vm.Save.Enable = _ => DateTime.Now.Hour => 5; | |
Vm.Changed.Callback = Changed; | |
} | |
private void Save() | |
{ | |
} | |
private void Changed() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="My_WPF_Project.Views.Header"> | |
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" | |
xmlns:local="clr-namespace:My_WPF_Project.Views" | |
xmlns:viewModels="clr-namespace:My_WPF_Project.ViewModels" | |
xmlns:interactivity="http://schemas.microsoft.com/expression/2010/interactivity" | |
mc:Ignorable="d" | |
d:DesignHeight="450" d:DesignWidth="450"> | |
<UserControl.DataContect> | |
<viewModels: vmHeader /> | |
</UserControl.DataContect> | |
<Grid> | |
<Button Command="{Binding Save}" Content=Save /> | |
<ComboBox> | |
<interactivity:Interaction.Triggers> | |
<interactivity:EventTrigger EventName="SelectionChanged"> | |
<interactivity:InvokeCommandAction Command="{Binding Changed}" /> | |
</interactivity:EventTrigger> | |
</interactivity:Interaction.Triggers> | |
</ComboBox> | |
</Grid> | |
</Usercontrol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="My_WPF_Project.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:My_WPF_Project" | |
xmlns:views="clr-namespace:My_WPF_Project.Views" | |
mc:Ignorable="d" | |
Title="Main Window" Height="850" Width="800"> | |
<DockPanel LastChildFill="True"> | |
<!-- Header --> | |
<views:Header x:Name="viewHeader" DockPanel.Dock="Top" Margin="6,0,6,0" /> | |
<!-- Footer --> | |
<views:Footer x:Name="viewFooter" DockPanel.Dock="Bottom" Margin="6,0,6,0" /> | |
<!-- Body --> | |
<views:Body x:Name="viewBody" Margin="6,0,6,0" /> | |
</DockPanel> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace My_WPF_Project | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
vmHeader vmHeader; | |
vmBody vmBody; | |
vmFooter; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
SetupViewModels(); | |
SetupControls(); | |
SetupRouter(); | |
SetupVMS(); | |
} | |
private void SetupViewModels() | |
{ | |
vmHeader = viewHeader.DataContext as ViewModels.vmHeader; | |
vmBody = viewBody.DataContext as ViewModels.vmBody; | |
vmFooter = viewFooter.DataContext as ViewModels.vmFooter; | |
} | |
private void SetupControls() | |
{ | |
new Controls.Header(vmHeader); | |
new Controls.Body(vmBody); | |
new Controls.Footer(vmFooter); | |
} | |
private void SetupRouter() | |
{ | |
new Router(vmHeader, vmBody, vmFooter); | |
} | |
private void SetupVMS() | |
{ | |
vms.Header = vmHeader; | |
vms.Body = vmBody; | |
vms.Footer = vmFooter; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace My_WPF_Project | |
{ | |
class RelayCommand : ICommand | |
{ | |
public Action CallBack { get; set; } | |
public Predicate<object> Enable { get; set; } | |
public event EventHandler CanExecuteChanged | |
{ | |
add { CommandManager.RequerySuggested += value; } | |
remove { CommandManager.RequerySuggested -= value; } | |
} | |
public bool CanExecute(object parameter) | |
{ | |
return Enable == null ? true : Enable(parameter); | |
} | |
public void Execute(object parameter = null) | |
{ | |
CallBack(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace My_WPF_Project | |
{ | |
public Router | |
{ | |
vmHeader Header { get; set; } | |
vmBody Body { get; set; } | |
vmFooter Footer { get; set; } | |
public Router(vmHeader header, vmBody body, vmFooter footer) | |
{ | |
Header = header; | |
Body = body; | |
Footer = footer; | |
Header.Save.Callback = Save(); | |
Header.Enable = _ => DateTime.Now.Hour => 5; | |
Header.Changed.Callback = Changed; | |
} | |
private void Save() | |
{ | |
} | |
private void Changed() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace My_WPF_Project.ViewModels | |
{ | |
class vmHeader | |
{ | |
public RelayCommand Save { get; private set; } | |
public RelayCommand Changed { get; private set; } | |
public vmHeader() | |
{ | |
Save = new RelayCommand(); | |
Save.CallBack = Save; | |
Save.Enable = _ => Datetime.Now.Hour => 5; | |
Changed = new RelayCommand(); | |
} | |
private void Save() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using My_WPF_Project.ViewModels; | |
namespace My_WPF_Project | |
{ | |
static class vms | |
{ | |
public static vmHeader Header { get; set; } | |
public static vmBody Body { get; set; } | |
public static vmFooter Footer { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment