- Reworked the view/vm structure
This commit is contained in:
parent
e935d01abc
commit
ef5e9afb89
|
@ -1,8 +1,8 @@
|
|||
<Application x:Class="Company.WpfApplication1.App"
|
||||
<Application x:Class="DynamicMenu.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:Company.WpfApplication1">
|
||||
xmlns:local="clr-namespace:DynamicMenu">
|
||||
<Application.Resources>
|
||||
<s:ApplicationLoader>
|
||||
<s:ApplicationLoader.Bootstrapper>
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Company.WpfApplication1
|
||||
namespace DynamicMenu
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using Company.WpfApplication1.Pages;
|
||||
using DynamicMenu.Pages;
|
||||
using Stylet;
|
||||
using StyletIoC;
|
||||
|
||||
namespace Company.WpfApplication1
|
||||
namespace DynamicMenu
|
||||
{
|
||||
public class Bootstrapper : Bootstrapper<ShellViewModel>
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<RootNamespace>DynamicMenu</RootNamespace>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using Stylet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DynamicMenu.Models
|
||||
{
|
||||
public class MainMenuItem
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Screen ViewModel { get; set; }
|
||||
public Action Method { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
using Stylet;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class Function1ViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<UserControl x:Class="DynamicMenu.Pages.MainMenuView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:DynamicMenu.Pages"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:MainMenuViewModel}"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" Orientation="Vertical" Margin="5">
|
||||
<TextBlock Text="COMPANY NAME" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="App Name" FontSize="12" HorizontalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding MenuItems}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,5">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="{Binding Title}" Width="200" Height="120" Margin="5" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -14,11 +14,11 @@ using System.Windows.Shapes;
|
|||
namespace DynamicMenu.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainView.xaml
|
||||
/// Interaction logic for MainMenuView.xaml
|
||||
/// </summary>
|
||||
public partial class MainView : UserControl
|
||||
public partial class MainMenuView : UserControl
|
||||
{
|
||||
public MainView()
|
||||
public MainMenuView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using DynamicMenu.Models;
|
||||
using Stylet;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class MainMenuViewModel : Screen
|
||||
{
|
||||
private ObservableCollection<MainMenuItem> _menuItems;
|
||||
public ObservableCollection<MainMenuItem> MenuItems
|
||||
{
|
||||
get { return _menuItems; }
|
||||
set { SetAndNotify(ref this._menuItems, value); }
|
||||
}
|
||||
|
||||
// ViewModel references
|
||||
public ShellViewModel ShellVM { get; }
|
||||
|
||||
// Default constructor
|
||||
public MainMenuViewModel()
|
||||
{
|
||||
MenuItems = new ObservableCollection<MainMenuItem>();
|
||||
MenuItems.Add(new MainMenuItem { Title = "Section 1", ViewModel = new Section001ViewModel() });
|
||||
MenuItems.Add(new MainMenuItem { Title = "Section 2", ViewModel = new Section002ViewModel() });
|
||||
MenuItems.Add(new MainMenuItem { Title = "Section 3", ViewModel = new Section003ViewModel() });
|
||||
}
|
||||
|
||||
public MainMenuViewModel(ShellViewModel shellVM) : this()
|
||||
{
|
||||
ShellVM = shellVM;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<UserControl x:Class="DynamicMenu.Pages.MainView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:DynamicMenu.Pages"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:MainViewModel}"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="COMPANY NAME" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,5" />
|
||||
<WrapPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,5">
|
||||
<WrapPanel.Resources>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Width" Value="200" />
|
||||
<Setter Property="Height" Value="120" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
</Style>
|
||||
</WrapPanel.Resources>
|
||||
<Button Content="Function 1" />
|
||||
<Button Content="Function 2" />
|
||||
<Button Content="Function 3" />
|
||||
</WrapPanel>
|
||||
<StatusBar Grid.Row="2">
|
||||
<StatusBarItem Content="Ready" />
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
using Stylet;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class MainViewModel : Conductor<IScreen>.StackNavigation
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
using Stylet;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class Section001ViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
using Stylet;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class Section002ViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
using Stylet;
|
||||
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class Section003ViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,12 +1,17 @@
|
|||
<Window x:Class="Company.WpfApplication1.Pages.ShellView"
|
||||
<Window x:Class="DynamicMenu.Pages.ShellView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:Company.WpfApplication1.Pages"
|
||||
xmlns:local="clr-namespace:DynamicMenu.Pages"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:ShellViewModel}"
|
||||
Title="Stylet Dynamic Menu" Height="600" Width="1200">
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||
<DockPanel>
|
||||
<StatusBar DockPanel.Dock="Bottom">
|
||||
<StatusBarItem Content="{Binding StatusMessage1}" />
|
||||
</StatusBar>
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||
</DockPanel>
|
||||
</Window>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Windows;
|
||||
|
||||
namespace Company.WpfApplication1.Pages
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ShellView.xaml
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
using DynamicMenu.Pages;
|
||||
using Stylet;
|
||||
using Stylet;
|
||||
|
||||
namespace Company.WpfApplication1.Pages
|
||||
namespace DynamicMenu.Pages
|
||||
{
|
||||
public class ShellViewModel : Conductor<IScreen>
|
||||
public class ShellViewModel : Conductor<IScreen>.StackNavigation
|
||||
{
|
||||
public MainViewModel MainVM { get; set; }
|
||||
// StatusBar
|
||||
private string _statusMessage1;
|
||||
public string StatusMessage1
|
||||
{
|
||||
get { return _statusMessage1; }
|
||||
set { SetAndNotify(ref this._statusMessage1, value); }
|
||||
}
|
||||
// ViewModel references
|
||||
public MainMenuViewModel MainMenuVM { get; }
|
||||
|
||||
// Default constructor
|
||||
public ShellViewModel()
|
||||
{
|
||||
MainVM = new MainViewModel();
|
||||
this.ActivateItem(MainVM);
|
||||
StatusMessage1 = "Ready";
|
||||
MainMenuVM = new MainMenuViewModel(this);
|
||||
this.ActivateItem(MainMenuVM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
|
||||
This solution contains multiple projects demonstrating the use of Stylet MVVM library for various use-cases.
|
||||
|
||||
---
|
||||
### Dynamic Menu
|
||||
The goal of this project is to dynamically create a side-menu for all ViewModels added to `Conductor<T>.Collection.OneActive` conductor.
|
Loading…
Reference in New Issue