Skip to content

Commit

Permalink
Add saving of size/location between app sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
joacand committed May 25, 2019
1 parent 6801f3c commit 714016f
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 9 deletions.
21 changes: 21 additions & 0 deletions VattenMedia/App.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="VattenMedia.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
Expand All @@ -10,4 +15,20 @@
<add key="TwitchEnabled" value="true"/>
<add key="YoutubeEnabled" value="true"/>
</appSettings>
<userSettings>
<VattenMedia.Properties.Settings>
<setting name="Height" serializeAs="String">
<value>400</value>
</setting>
<setting name="Width" serializeAs="String">
<value>750</value>
</setting>
<setting name="Top" serializeAs="String">
<value>0</value>
</setting>
<setting name="Left" serializeAs="String">
<value>0</value>
</setting>
</VattenMedia.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion VattenMedia/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Application x:Class="VattenMedia.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VattenMedia">
xmlns:local="clr-namespace:VattenMedia"
Exit="Application_Exit">
<Application.Resources>

</Application.Resources>
Expand Down
5 changes: 5 additions & 0 deletions VattenMedia/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ protected override void OnStartup(StartupEventArgs e)
var window = new MainWindow { DataContext = mainWindowViewModel };
window.Show();
}

private void Application_Exit(object sender, ExitEventArgs e)
{
VattenMedia.Properties.Settings.Default.Save();
}
}
}
24 changes: 24 additions & 0 deletions VattenMedia/MarkupExtensions/SettingBindingExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Windows.Data;

namespace VattenMedia.MarkupExtensions
{
public class SettingBindingExtension : Binding
{
public SettingBindingExtension()
{
Initialize();
}

public SettingBindingExtension(string path)
: base(path)
{
Initialize();
}

private void Initialize()
{
Source = Properties.Settings.Default;
Mode = BindingMode.TwoWay;
}
}
}
50 changes: 49 additions & 1 deletion VattenMedia/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions VattenMedia/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="VattenMedia.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="Height" Type="System.Double" Scope="User">
<Value Profile="(Default)">400</Value>
</Setting>
<Setting Name="Width" Type="System.Double" Scope="User">
<Value Profile="(Default)">750</Value>
</Setting>
<Setting Name="Top" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Left" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
1 change: 1 addition & 0 deletions VattenMedia/VattenMedia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
</ApplicationDefinition>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Converters\EnumMatchToBooleanConverter.cs" />
<Compile Include="MarkupExtensions\SettingBindingExtension.cs" />
<Compile Include="Models\LiveChannel.cs" />
<Compile Include="Models\RelayCommand.cs" />
<Compile Include="ViewModels\BaseViewModel.cs" />
Expand Down
9 changes: 7 additions & 2 deletions VattenMedia/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="clr-namespace:VattenMedia.Converters"
xmlns:markupExtensions="clr-namespace:VattenMedia.MarkupExtensions"
mc:Ignorable="d"
Title="VattenMedia" Height="750" Width="1400"
Title="VattenMedia"
FontSize="14"
Background="{DynamicResource BG}"
Foreground="White">
Foreground="White"
Height="{markupExtensions:SettingBinding Height}"
Width="{markupExtensions:SettingBinding Width}"
Left="{markupExtensions:SettingBinding Left}"
Top="{markupExtensions:SettingBinding Top}">
<Window.Resources>
<SolidColorBrush x:Key="BG" Color="#574692"></SolidColorBrush>
<SolidColorBrush x:Key="SBG" Color="#232031"></SolidColorBrush>
Expand Down

0 comments on commit 714016f

Please sign in to comment.