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:
parent
a3d3a15a88
commit
420792e478
@ -23,17 +23,19 @@ namespace Artemis.UI
|
|||||||
this.WhenAnyValue(x => x.Router.CurrentViewModel)
|
this.WhenAnyValue(x => x.Router.CurrentViewModel)
|
||||||
.Subscribe(o => o.Subscribe(vm => { ViewTitle = vm != null ? vm.UrlPathSegment : ""; }));
|
.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
|
// Navigate to the opening page of the application
|
||||||
Router.Navigate.Execute(Kernel.Get<IMainViewModel>());
|
Router.Navigate.Execute(Kernel.Get<IMainViewModel>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IKernel Kernel { get; set; }
|
public IKernel Kernel { get; set; }
|
||||||
|
public ISidebarViewModel SidebarViewModel { get; }
|
||||||
|
public RoutingState Router { get; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string ViewTitle { get; set; }
|
public string ViewTitle { get; set; }
|
||||||
|
|
||||||
public RoutingState Router { get; }
|
|
||||||
|
|
||||||
private void SetupNinject(IKernel kernel)
|
private void SetupNinject(IKernel kernel)
|
||||||
{
|
{
|
||||||
// Bind the main screen to IScreen
|
// Bind the main screen to IScreen
|
||||||
|
|||||||
@ -101,10 +101,15 @@
|
|||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="AppBootstrapper.cs" />
|
<Compile Include="AppBootstrapper.cs" />
|
||||||
<Compile Include="Ninject\ViewsModule.cs" />
|
<Compile Include="Ninject\ViewsModule.cs" />
|
||||||
|
<Compile Include="ViewModels\Interfaces\IArtemisViewModel.cs" />
|
||||||
<Compile Include="ViewModels\MainViewModel.cs" />
|
<Compile Include="ViewModels\MainViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\SidebarViewModel.cs" />
|
||||||
<Compile Include="Views\MainView.xaml.cs">
|
<Compile Include="Views\MainView.xaml.cs">
|
||||||
<DependentUpon>MainView.xaml</DependentUpon>
|
<DependentUpon>MainView.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Views\SidebarView.xaml.cs">
|
||||||
|
<DependentUpon>SidebarView.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Page Include="MainWindow.xaml">
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
@ -121,6 +126,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Views\SidebarView.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
@ -163,9 +172,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Resources\bow.svg" />
|
<None Include="Resources\bow.svg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="ViewModels\Interfaces\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="FodyWeavers.xml" />
|
<None Include="FodyWeavers.xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -73,13 +73,7 @@
|
|||||||
DockPanel.Dock="Top"
|
DockPanel.Dock="Top"
|
||||||
HorizontalAlignment="Right" Margin="16"
|
HorizontalAlignment="Right" Margin="16"
|
||||||
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
|
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
|
||||||
<ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0">
|
<views:SidebarView DataContext="{Binding SidebarViewModel}"></views:SidebarView>
|
||||||
<ListBox.ItemTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<TextBlock Text="{Binding Name}" Margin="32 0 32 0" />
|
|
||||||
</DataTemplate>
|
|
||||||
</ListBox.ItemTemplate>
|
|
||||||
</ListBox>
|
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</materialDesign:DrawerHost.LeftDrawerContent>
|
</materialDesign:DrawerHost.LeftDrawerContent>
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
|
|||||||
@ -8,6 +8,7 @@ namespace Artemis.UI.Ninject
|
|||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
Bind<IMainViewModel>().To<MainViewModel>();
|
Bind<IMainViewModel>().To<MainViewModel>();
|
||||||
|
Bind<ISidebarViewModel>().To<SidebarViewModel>().InSingletonScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
src/Artemis.UI/ViewModels/Interfaces/IArtemisViewModel.cs
Normal file
10
src/Artemis.UI/ViewModels/Interfaces/IArtemisViewModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace Artemis.UI.ViewModels.Interfaces
|
||||||
|
{
|
||||||
|
public interface IArtemisViewModel : IRoutableViewModel
|
||||||
|
{
|
||||||
|
string Title { get; }
|
||||||
|
string Icon { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,19 +1,26 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Artemis.UI.ViewModels.Interfaces;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace Artemis.UI.ViewModels
|
namespace Artemis.UI.ViewModels
|
||||||
{
|
{
|
||||||
public class MainViewModel : ReactiveObject, IMainViewModel
|
public class MainViewModel : ReactiveObject, IMainViewModel
|
||||||
{
|
{
|
||||||
public MainViewModel(IScreen screen)
|
public MainViewModel(IScreen screen, ISidebarViewModel sidebarViewModel)
|
||||||
{
|
{
|
||||||
HostScreen = screen;
|
HostScreen = screen;
|
||||||
OpenUrl = ReactiveCommand.CreateFromTask<string>(OpenUrlAsync);
|
OpenUrl = ReactiveCommand.CreateFromTask<string>(OpenUrlAsync);
|
||||||
|
|
||||||
|
// Add this view as a menu item
|
||||||
|
sidebarViewModel.MenuItems.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScreen HostScreen { get; }
|
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; }
|
public ReactiveCommand OpenUrl { get; }
|
||||||
|
|
||||||
private async Task OpenUrlAsync(string url)
|
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; }
|
ReactiveCommand OpenUrl { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/Artemis.UI/ViewModels/SidebarViewModel.cs
Normal file
23
src/Artemis.UI/ViewModels/SidebarViewModel.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/Artemis.UI/Views/SidebarView.xaml
Normal file
22
src/Artemis.UI/Views/SidebarView.xaml
Normal 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>
|
||||||
30
src/Artemis.UI/Views/SidebarView.xaml.cs
Normal file
30
src/Artemis.UI/Views/SidebarView.xaml.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user