1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Some UI stuff

This commit is contained in:
SpoinkyNL 2017-12-25 19:10:28 +01:00
parent a3d3a15a88
commit 420792e478
9 changed files with 111 additions and 15 deletions

View File

@ -23,17 +23,19 @@ namespace Artemis.UI
this.WhenAnyValue(x => x.Router.CurrentViewModel)
.Subscribe(o => o.Subscribe(vm => { ViewTitle = vm != null ? vm.UrlPathSegment : ""; }));
// Setup the sidebar that lives throughout the app
SidebarViewModel = Kernel.Get<ISidebarViewModel>();
// Navigate to the opening page of the application
Router.Navigate.Execute(Kernel.Get<IMainViewModel>());
}
public IKernel Kernel { get; set; }
public ISidebarViewModel SidebarViewModel { get; }
public RoutingState Router { get; }
[Reactive]
public string ViewTitle { get; set; }
public RoutingState Router { get; }
private void SetupNinject(IKernel kernel)
{
// Bind the main screen to IScreen

View File

@ -101,10 +101,15 @@
</ApplicationDefinition>
<Compile Include="AppBootstrapper.cs" />
<Compile Include="Ninject\ViewsModule.cs" />
<Compile Include="ViewModels\Interfaces\IArtemisViewModel.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\SidebarViewModel.cs" />
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SidebarView.xaml.cs">
<DependentUpon>SidebarView.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -121,6 +126,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SidebarView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
@ -163,9 +172,7 @@
<ItemGroup>
<None Include="Resources\bow.svg" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewModels\Interfaces\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="FodyWeavers.xml" />
</ItemGroup>

View File

@ -73,13 +73,7 @@
DockPanel.Dock="Top"
HorizontalAlignment="Right" Margin="16"
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
<ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Margin="32 0 32 0" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<views:SidebarView DataContext="{Binding SidebarViewModel}"></views:SidebarView>
</DockPanel>
</materialDesign:DrawerHost.LeftDrawerContent>
<DockPanel>

View File

@ -8,6 +8,7 @@ namespace Artemis.UI.Ninject
public override void Load()
{
Bind<IMainViewModel>().To<MainViewModel>();
Bind<ISidebarViewModel>().To<SidebarViewModel>().InSingletonScope();
}
}
}

View File

@ -0,0 +1,10 @@
using ReactiveUI;
namespace Artemis.UI.ViewModels.Interfaces
{
public interface IArtemisViewModel : IRoutableViewModel
{
string Title { get; }
string Icon { get; }
}
}

View File

@ -1,19 +1,26 @@
using System.Diagnostics;
using System.Threading.Tasks;
using Artemis.UI.ViewModels.Interfaces;
using ReactiveUI;
namespace Artemis.UI.ViewModels
{
public class MainViewModel : ReactiveObject, IMainViewModel
{
public MainViewModel(IScreen screen)
public MainViewModel(IScreen screen, ISidebarViewModel sidebarViewModel)
{
HostScreen = screen;
OpenUrl = ReactiveCommand.CreateFromTask<string>(OpenUrlAsync);
// Add this view as a menu item
sidebarViewModel.MenuItems.Add(this);
}
public IScreen HostScreen { get; }
public string UrlPathSegment => "Home";
public string UrlPathSegment => Title.ToLower();
public string Title => "Home";
public string Icon => "Home";
public ReactiveCommand OpenUrl { get; }
private async Task OpenUrlAsync(string url)
@ -22,7 +29,7 @@ namespace Artemis.UI.ViewModels
}
}
public interface IMainViewModel : IRoutableViewModel
public interface IMainViewModel : IArtemisViewModel
{
ReactiveCommand OpenUrl { get; }
}

View File

@ -0,0 +1,23 @@
using System.Collections.ObjectModel;
using Artemis.UI.ViewModels.Interfaces;
using ReactiveUI;
namespace Artemis.UI.ViewModels
{
public class SidebarViewModel : ReactiveObject, ISidebarViewModel
{
public SidebarViewModel(IScreen screen)
{
HostScreen = screen;
MenuItems = new ObservableCollection<IArtemisViewModel>();
}
public IScreen HostScreen { get; }
public ObservableCollection<IArtemisViewModel> MenuItems { get; set; }
}
public interface ISidebarViewModel
{
ObservableCollection<IArtemisViewModel> MenuItems { get; set; }
}
}

View File

@ -0,0 +1,22 @@
<UserControl x:Class="Artemis.UI.Views.SidebarView"
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:interfaces="clr-namespace:Artemis.UI.ViewModels.Interfaces"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ListBox Margin="0 16 0 16"
SelectedIndex="0"
ItemsSource="{Binding MenuItems}">
<ListBox.ItemTemplate>
<DataTemplate DataType="interfaces:IArtemisViewModel">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="{Binding Icon}" />
<TextBlock Text="{Binding Title}" Margin="32 0 32 0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</UserControl>

View File

@ -0,0 +1,30 @@
using System.Windows;
using System.Windows.Controls;
using Artemis.UI.ViewModels;
using ReactiveUI;
namespace Artemis.UI.Views
{
/// <summary>
/// Interaction logic for SidebarView.xaml
/// </summary>
public partial class SidebarView : UserControl, IViewFor<ISidebarViewModel>
{
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(ISidebarViewModel), typeof(SidebarView), new PropertyMetadata(null));
public SidebarView()
{
InitializeComponent();
this.WhenAnyValue(x => x.ViewModel).BindTo(this, x => x.DataContext);
}
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (ISidebarViewModel)value;
}
public ISidebarViewModel ViewModel { get; set; }
}
}