Browse Source

Introduce basic MVVM pattern to avoid interferences of content and control style

pull/2347/head
tom-englert 4 years ago
parent
commit
157d5fe9c2
  1. 41
      ILSpy/Options/DisplaySettingsPanel.xaml
  2. 16
      ILSpy/Options/OptionsDialog.xaml
  3. 21
      ILSpy/Options/OptionsDialog.xaml.cs

41
ILSpy/Options/DisplaySettingsPanel.xaml

@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
xmlns:local="clr-namespace:ICSharpCode.ILSpy.Options">
xmlns:local="clr-namespace:ICSharpCode.ILSpy.Options"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<UserControl.Resources>
<local:FontSizeConverter x:Key="fontSizeConv" />
</UserControl.Resources>
@ -35,25 +36,25 @@ @@ -35,25 +36,25 @@
</ComboBox>
<Label Grid.Column="2" Margin="3,0" Content="{x:Static properties:Resources.Size}"></Label>
<ComboBox Grid.Column="3" Text="{Binding SelectedFontSize, Converter={StaticResource fontSizeConv}}" IsEditable="True" Margin="3,0">
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>9</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>11</ComboBoxItem>
<ComboBoxItem>12</ComboBoxItem>
<ComboBoxItem>13</ComboBoxItem>
<ComboBoxItem>14</ComboBoxItem>
<ComboBoxItem>15</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
<ComboBoxItem>17</ComboBoxItem>
<ComboBoxItem>18</ComboBoxItem>
<ComboBoxItem>19</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
<ComboBoxItem>21</ComboBoxItem>
<ComboBoxItem>22</ComboBoxItem>
<ComboBoxItem>23</ComboBoxItem>
<ComboBoxItem>24</ComboBoxItem>
<system:Int32>6</system:Int32>
<system:Int32>7</system:Int32>
<system:Int32>8</system:Int32>
<system:Int32>9</system:Int32>
<system:Int32>10</system:Int32>
<system:Int32>11</system:Int32>
<system:Int32>12</system:Int32>
<system:Int32>13</system:Int32>
<system:Int32>14</system:Int32>
<system:Int32>15</system:Int32>
<system:Int32>16</system:Int32>
<system:Int32>17</system:Int32>
<system:Int32>18</system:Int32>
<system:Int32>19</system:Int32>
<system:Int32>20</system:Int32>
<system:Int32>21</system:Int32>
<system:Int32>22</system:Int32>
<system:Int32>23</system:Int32>
<system:Int32>24</system:Int32>
</ComboBox>
<Border Grid.Row="1" Grid.ColumnSpan="4" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="1" Margin="3,5">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="AaBbCcXxYyZz" FontFamily="{Binding SelectedFont}" FontSize="{Binding SelectedFontSize}" />

16
ILSpy/Options/OptionsDialog.xaml

@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
Style="{DynamicResource DialogWindow}"
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options"
Style="{DynamicResource DialogWindow}"
WindowStartupLocation="CenterOwner"
ResizeMode="CanResizeWithGrip"
Title="{x:Static properties:Resources.Options}" Height="500" Width="600">
@ -13,7 +14,18 @@ @@ -13,7 +14,18 @@
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<TabControl Name="tabControl" />
<TabControl Name="tabControl" SelectedValuePath="Content">
<TabControl.ItemTemplate>
<DataTemplate DataType="options:TabItemViewModel">
<TextBlock Text="{Binding Header}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate DataType="options:TabItemViewModel">
<ContentPresenter Content="{Binding Content}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="12,8">
<Button Margin="2,0" Name="defaultsButton" Click="DefaultsButton_Click" Content="{x:Static properties:Resources.ResetToDefaults}" />
<Button IsDefault="True" Margin="2,0" Name="okButton" Click="OKButton_Click" Content="{x:Static properties:Resources.OK}" />

21
ILSpy/Options/OptionsDialog.xaml.cs

@ -21,12 +21,26 @@ using System.ComponentModel.Composition; @@ -21,12 +21,26 @@ using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Xml.Linq;
using ICSharpCode.ILSpy.Properties;
namespace ICSharpCode.ILSpy.Options
{
public class TabItemViewModel
{
public TabItemViewModel(string header, UIElement content)
{
Header = header;
Content = content;
}
public string Header { get; }
public UIElement Content { get; }
}
/// <summary>
/// Interaction logic for OptionsDialog.xaml
/// </summary>
@ -46,9 +60,8 @@ namespace ICSharpCode.ILSpy.Options @@ -46,9 +60,8 @@ namespace ICSharpCode.ILSpy.Options
ILSpySettings settings = ILSpySettings.Load();
foreach (var optionPage in optionPages.OrderBy(p => p.Metadata.Order))
{
TabItem tabItem = new TabItem();
tabItem.Header = MainWindow.GetResourceString(optionPage.Metadata.Title);
tabItem.Content = optionPage.Value;
var tabItem = new TabItemViewModel(MainWindow.GetResourceString(optionPage.Metadata.Title), optionPage.Value);
tabControl.Items.Add(tabItem);
IOptionPage page = optionPage.Value as IOptionPage;
@ -76,7 +89,7 @@ namespace ICSharpCode.ILSpy.Options @@ -76,7 +89,7 @@ namespace ICSharpCode.ILSpy.Options
{
if (MessageBox.Show(Properties.Resources.ResetToDefaultsConfirmationMessage, "ILSpy", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
var page = ((TabItem)tabControl.SelectedItem).Content as IOptionPage;
var page = tabControl.SelectedValue as IOptionPage;
if (page != null)
page.LoadDefaults();
}

Loading…
Cancel
Save