- 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"/>
</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}">
<Border Width="100" Height="400" Margin="10" BorderThickness="1" BorderBrush="{StaticResource ChannelForeground}">
<Button Command="{Binding SelectControllableCommand}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<ContentControl Template="{StaticResource Add}"
Height="40" Width="40"
HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="{StaticResource ChannelForeground}"
IsVisible="{Binding !IsControllableMapped}"/>
<ContentControl Content="{Binding Controllable}"
ContentTemplate="{StaticResource ControllableTemplate}"
IsVisible="{Binding IsControllableMapped}"/>
</Grid>
</Button>
</Border>
</DataTemplate>

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

@ -6,12 +6,17 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Lib.Audio.Interfaces;
using Mystify.Views;
using ReactiveUI;
namespace Mystify.ViewModels
{
public class ControllableSelectionViewModel : ViewModelBase
{
private readonly ControllableSelectionWindow? _window;
public ControllableSelectionViewModel()
{
if (!IsInDesignMode)
@ -20,8 +25,10 @@ namespace Mystify.ViewModels
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.Select(c => new ControllableViewModel(c)).ToObservableCollection();
@ -30,8 +37,11 @@ namespace Mystify.ViewModels
}
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)
{
if (!isSelected)
@ -41,6 +51,7 @@ namespace Mystify.ViewModels
return;
SelectedControllable = controllableViewModel;
CloseWindow();
}
}
}

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

Loading…
Cancel
Save