Skip to content

Commit

Permalink
Set up basic MVVM implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
skiwi2 committed Dec 27, 2016
1 parent 98bde1d commit db567e9
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 8 deletions.
3 changes: 1 addition & 2 deletions ArenaDraftAssistant/App.xaml
@@ -1,8 +1,7 @@
<Application x:Class="ArenaDraftAssistant.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ArenaDraftAssistant"
StartupUri="MainWindow.xaml">
xmlns:local="clr-namespace:ArenaDraftAssistant">
<Application.Resources>

</Application.Resources>
Expand Down
7 changes: 7 additions & 0 deletions ArenaDraftAssistant/App.xaml.cs
Expand Up @@ -13,5 +13,12 @@ namespace ArenaDraftAssistant
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var window = new MainWindow { DataContext = new MainWindowViewModel() };
window.Show();
}
}
}
31 changes: 31 additions & 0 deletions ArenaDraftAssistant/ArenaDraftAssistant.csproj
Expand Up @@ -34,6 +34,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand All @@ -59,6 +79,13 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="SelectHeroClassModel.cs" />
<Compile Include="SelectHeroClassViewModel.cs" />
<Compile Include="SelectHeroClassView.xaml.cs">
<DependentUpon>SelectHeroClassView.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModelBase.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -71,6 +98,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="SelectHeroClassView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Model\HeroClass.cs" />
Expand Down
7 changes: 6 additions & 1 deletion ArenaDraftAssistant/MainWindow.xaml
Expand Up @@ -6,12 +6,17 @@
xmlns:local="clr-namespace:ArenaDraftAssistant"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type local:SelectHeroClassViewModel}">
<local:SelectHeroClassView/>
</DataTemplate>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_Quit" Click="FileQuit_OnClick"/>
</MenuItem>
</Menu>
<StackPanel/>
<ContentPresenter Content="{Binding Path=CurrentViewModel}"/>
</DockPanel>
</Window>
8 changes: 3 additions & 5 deletions ArenaDraftAssistant/MainWindow.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -18,16 +19,13 @@ namespace ArenaDraftAssistant
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void FileQuit_OnClick(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void FileQuit_OnClick(object sender, RoutedEventArgs e) => Application.Current.Shutdown();
}
}
30 changes: 30 additions & 0 deletions ArenaDraftAssistant/MainWindowViewModel.cs
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArenaDraftAssistant
{
class MainWindowViewModel : ViewModelBase
{
public MainWindowViewModel()
{
LoadSelectHeroClassPage();
}

private ViewModelBase _currentViewModel;

public ViewModelBase CurrentViewModel
{
get { return _currentViewModel; }
set
{
_currentViewModel = value;
OnPropertyChanged(nameof(CurrentViewModel));
}
}

private void LoadSelectHeroClassPage() => CurrentViewModel = new SelectHeroClassViewModel(new SelectHeroClassModel());
}
}
16 changes: 16 additions & 0 deletions ArenaDraftAssistant/SelectHeroClassModel.cs
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArenaDraftAssistant.Model;

namespace ArenaDraftAssistant
{
class SelectHeroClassModel
{
// TODO add list of HeroClass to back a select box

public HeroClass SelectedHeroClass { get; set; }
}
}
12 changes: 12 additions & 0 deletions ArenaDraftAssistant/SelectHeroClassView.xaml
@@ -0,0 +1,12 @@
<UserControl x:Class="ArenaDraftAssistant.SelectHeroClassView"
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:ArenaDraftAssistant"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Label Content="Test"></Label>
</Grid>
</UserControl>
28 changes: 28 additions & 0 deletions ArenaDraftAssistant/SelectHeroClassView.xaml.cs
@@ -0,0 +1,28 @@
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 ArenaDraftAssistant
{
/// <summary>
/// Interaction logic for SelectHeroView.xaml
/// </summary>
public partial class SelectHeroClassView : UserControl
{
public SelectHeroClassView()
{
InitializeComponent();
}
}
}
29 changes: 29 additions & 0 deletions ArenaDraftAssistant/SelectHeroClassViewModel.cs
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArenaDraftAssistant.Model;

namespace ArenaDraftAssistant
{
class SelectHeroClassViewModel : ViewModelBase
{
public SelectHeroClassModel Model { get; private set; }

public SelectHeroClassViewModel(SelectHeroClassModel model)
{
Model = model;
}

public HeroClass SelectedHeroClass
{
get { return Model.SelectedHeroClass; }
set
{
Model.SelectedHeroClass = value;
OnPropertyChanged(nameof(SelectedHeroClass));
}
}
}
}
24 changes: 24 additions & 0 deletions ArenaDraftAssistant/ViewModelBase.cs
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArenaDraftAssistant
{
class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChanged?.Invoke(this, e);
}
}
}

0 comments on commit db567e9

Please sign in to comment.