HeadMeld 0.0.0.1

- Working MVVM implementation
- Refactored code
This commit is contained in:
2022-03-27 22:20:56 +01:00
parent ae9fbc6d97
commit 67f440e7e8
7 changed files with 131 additions and 79 deletions
+2 -2
View File
@@ -7,12 +7,12 @@
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Compile Update="MainWindow.xaml.cs">
<Compile Update="Views\MainWindowView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="MainWindow.xaml">
<Page Update="Views\MainWindowView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Startup.xaml">
-22
View File
@@ -1,22 +0,0 @@
<Window x:Class="HeadMeld.MainWindow"
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:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
mc:Ignorable="d" Height="450" Width="300"
Loaded="Window_Loaded" ResizeMode="NoResize" ShowInTaskbar="False" Activated="Window_Activated" Closing="Window_Closing">
<Grid>
<ui:SimpleStackPanel Margin="12" Spacing="24" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True">
<TextBlock Text="🎧HeadMeld" Style="{StaticResource HeaderTextBlockStyle}" />
<ui:NavigationViewItemHeader Content="Equalizer APO Status"/>
<ui:ToggleSwitch Margin="15,-15,0,0" x:Name="toggleAPOEnabled" HorizontalAlignment="Stretch" OffContent="Disabled" OnContent="Enabled" Toggled="toggleAPOEnabled_Toggled"/>
<ui:NavigationViewItemHeader Content="Selected Profile"/>
<ui:RadioButtons x:Name="btnRadioProfiles" Margin="15,-15,0,0" d:ItemsSource="{d:SampleData ItemCount=2}" SelectedIndex="0" HorizontalAlignment="Stretch" />
<Button x:Name="btnExit" Content="Exit" HorizontalAlignment="Stretch" Click="btnExit_Click" />
</ui:SimpleStackPanel>
</Grid>
</Window>
-55
View File
@@ -1,55 +0,0 @@
using System.Collections.Generic;
using System.Windows;
namespace HeadMeld
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
ConfigManager configManager = new();
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in configManager.configFile)
{
btnRadioProfiles.Items.Add(item);
}
}
private void btnExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void Window_Activated(object sender, System.EventArgs e)
{
// Set window position based on taskbar location
var desktopWorkArea = SystemParameters.WorkArea;
Left = desktopWorkArea.Right - Width - 15;
Top = desktopWorkArea.Bottom - Height - 15;
}
private void toggleAPOEnabled_Toggled(object sender, RoutedEventArgs e)
{
configManager.ToggleProfiles(new List<string>
{
"# Include: ATH-M50x.txt",
"Include: 900ProX.txt"
},
toggleAPOEnabled.IsOn);
configManager.Write();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Visibility = Visibility.Collapsed;
e.Cancel = true;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HeadMeld.Models
{
sealed class MainWindowModel
{
public bool ToggleAPOEnabled { get; set; }
public List<string> Profiles { get; set; }
}
}
+50
View File
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.ComponentModel;
using HeadMeld.Models;
namespace HeadMeld.ViewModels
{
sealed class MainWindowViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChange(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private MainWindowModel _model = new();
public bool ToggleAPOEnabled
{
get { return _model.ToggleAPOEnabled; }
set
{
if (_model.ToggleAPOEnabled != value)
{
_model.ToggleAPOEnabled = value;
OnPropertyChange(nameof(ToggleAPOEnabled));
}
}
}
public List<string> Profiles
{
get { return _model.Profiles; }
set
{
if (_model.Profiles != value)
{
_model.Profiles = value;
OnPropertyChange(nameof(Profiles));
}
}
}
public MainWindowViewModel()
{
_model = new()
{
ToggleAPOEnabled = true,
Profiles = new List<string>() { "1", "2"}
};
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<Window x:Class="HeadMeld.MainWindow"
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:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
mc:Ignorable="d" Height="450" Width="300"
ResizeMode="NoResize" ShowInTaskbar="False">
<Grid>
<!-- Window Stack Panel-->
<ui:SimpleStackPanel
Margin="12" Spacing="20"
ScrollViewer.VerticalScrollBarVisibility="Auto" >
<!-- Window Header-->
<TextBlock Text="🎧HeadMeld"
Style="{StaticResource HeaderTextBlockStyle}" />
<!-- Equalizer APO Status -->
<ui:NavigationViewItemHeader Content="Equalizer APO Status"/>
<ui:ToggleSwitch x:Name="ToggleAPOEnabled"
Margin="15,-15,0,0"
HorizontalAlignment="Stretch"
OffContent="Disabled" OnContent="Enabled"
IsOn="{Binding ToggleAPOEnabled,
UpdateSourceTrigger=PropertyChanged}"/>
<!-- Selected Profile-->
<ui:NavigationViewItemHeader Content="Selected Profile"/>
<ui:RadioButtons x:Name="btnRadioProfiles"
Margin="15,-15,0,0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Profiles,
UpdateSourceTrigger=PropertyChanged}" />
<!-- Window Controls -->
<Button x:Name="btnExit"
Margin="15,0,15,0"
HorizontalAlignment="Stretch"
Content="Exit" />
</ui:SimpleStackPanel>
</Grid>
</Window>
+21
View File
@@ -0,0 +1,21 @@
using System.Windows;
using HeadMeld.ViewModels;
namespace HeadMeld
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly MainWindowViewModel viewModel;
public MainWindow()
{
InitializeComponent();
viewModel = new MainWindowViewModel();
DataContext = viewModel;
}
}
}