- first working solution of new ui

master
Simon G 5 years ago
parent 4b3387dd20
commit 9d669fc04a
  1. 10
      Mystify/Resources/ChannelTemplate.axaml
  2. 11
      Mystify/ViewModels/ChannelViewModel.cs
  3. 15
      Mystify/ViewModels/ControllableSelectionViewModel.cs
  4. 4
      Mystify/Views/ControllableSelectionWindow.axaml

@ -11,16 +11,26 @@
<ResourceInclude Source="/Resources/Icons/Icons.axaml"/> <ResourceInclude Source="/Resources/Icons/Icons.axaml"/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="ControllableTemplate" DataType="{x:Type viewModels:ControllableViewModel}">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
<DataTemplate x:Key="ChannelTemplate" DataType="{x:Type viewModels:ChannelViewModel}"> <DataTemplate x:Key="ChannelTemplate" DataType="{x:Type viewModels:ChannelViewModel}">
<Border Width="100" Height="400" Margin="10" BorderThickness="1" BorderBrush="{StaticResource ChannelForeground}"> <Border Width="100" Height="400" Margin="10" BorderThickness="1" BorderBrush="{StaticResource ChannelForeground}">
<Button Command="{Binding SelectControllableCommand}" <Button Command="{Binding SelectControllableCommand}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<ContentControl Template="{StaticResource Add}" <ContentControl Template="{StaticResource Add}"
Height="40" Width="40" Height="40" Width="40"
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="{StaticResource ChannelForeground}" Foreground="{StaticResource ChannelForeground}"
IsVisible="{Binding !IsControllableMapped}"/> IsVisible="{Binding !IsControllableMapped}"/>
<ContentControl Content="{Binding Controllable}"
ContentTemplate="{StaticResource ControllableTemplate}"
IsVisible="{Binding IsControllableMapped}"/>
</Grid>
</Button> </Button>
</Border> </Border>
</DataTemplate> </DataTemplate>

@ -31,6 +31,9 @@ namespace Mystify.ViewModels
{ {
if (value != null) if (value != null)
Channel.MapControllable(value.Controllable); Channel.MapControllable(value.Controllable);
RaisePropertyChanged(() => Controllable);
RaisePropertyChanged(() => IsControllableMapped);
} }
} }
@ -40,11 +43,9 @@ namespace Mystify.ViewModels
private async Task SelectControllable() private async Task SelectControllable()
{ {
ControllableSelectionWindow controllableSelectionWindow = ControllableSelectionWindow controllableSelectionWindow = new();
new() ControllableSelectionViewModel controllableSelectionViewModel = new(_mainModel.Controllables, controllableSelectionWindow);
{ controllableSelectionWindow.DataContext = controllableSelectionViewModel;
DataContext = new ControllableSelectionViewModel(_mainModel.Controllables)
};
Controllable = await controllableSelectionWindow.ShowDialog<ControllableViewModel>(_mainWindow); Controllable = await controllableSelectionWindow.ShowDialog<ControllableViewModel>(_mainWindow);
} }

@ -6,12 +6,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Windows.Input;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Mystify.Views;
using ReactiveUI;
namespace Mystify.ViewModels namespace Mystify.ViewModels
{ {
public class ControllableSelectionViewModel : ViewModelBase public class ControllableSelectionViewModel : ViewModelBase
{ {
private readonly ControllableSelectionWindow? _window;
public ControllableSelectionViewModel() public ControllableSelectionViewModel()
{ {
if (!IsInDesignMode) if (!IsInDesignMode)
@ -20,8 +25,10 @@ namespace Mystify.ViewModels
Controllables = new ObservableCollection<ControllableViewModel>(); Controllables = new ObservableCollection<ControllableViewModel>();
} }
public ControllableSelectionViewModel(List<IControllable>? controllables) public ControllableSelectionViewModel(List<IControllable>? controllables, ControllableSelectionWindow window)
{ {
_window = window;
Controllables = controllables == null ? new ObservableCollection<ControllableViewModel>() : Controllables = controllables == null ? new ObservableCollection<ControllableViewModel>() :
controllables.Select(c => new ControllableViewModel(c)).ToObservableCollection(); controllables.Select(c => new ControllableViewModel(c)).ToObservableCollection();
@ -30,8 +37,11 @@ namespace Mystify.ViewModels
} }
public ObservableCollection<ControllableViewModel> Controllables { get; } public ObservableCollection<ControllableViewModel> Controllables { get; }
public ControllableViewModel? SelectedControllable { get; private set; } private ControllableViewModel? SelectedControllable { get; set; }
public ICommand CloseCommand => ReactiveCommand.Create(CloseWindow);
private void CloseWindow() => _window?.Close(SelectedControllable);
private void OnControllableSelected(object? sender, bool isSelected) private void OnControllableSelected(object? sender, bool isSelected)
{ {
if (!isSelected) if (!isSelected)
@ -41,6 +51,7 @@ namespace Mystify.ViewModels
return; return;
SelectedControllable = controllableViewModel; SelectedControllable = controllableViewModel;
CloseWindow();
} }
} }
} }

@ -15,6 +15,10 @@
<viewModels:ControllableSelectionViewModel/> <viewModels:ControllableSelectionViewModel/>
</Design.DataContext> </Design.DataContext>
<Window.KeyBindings>
<KeyBinding Gesture="Escape" Command="{Binding CloseCommand}"/>
</Window.KeyBindings>
<Window.DataTemplates> <Window.DataTemplates>
<DataTemplate DataType="viewModels:ControllableViewModel"> <DataTemplate DataType="viewModels:ControllableViewModel">
<Button Command="{Binding SelectCommand}" HorizontalAlignment="Stretch"> <Button Command="{Binding SelectCommand}" HorizontalAlignment="Stretch">

Loading…
Cancel
Save