Skip to content

Commit

Permalink
Provide API to enable compact in app level.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Oct 22, 2019
1 parent f2d0cbd commit 0e204ab
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 57 deletions.
36 changes: 0 additions & 36 deletions ModernWpf.SampleApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,6 @@
<SolidColorBrush x:Key="CustomThemeBrush" Color="Blue" />
</ResourceDictionary>
</ui:ThemeResources.ThemeDictionaries>
<!--<ResourceDictionary.MergedDictionaries>
<ui:ThemeDictionary Key="Light">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:DefaultThemeResources Key="Light" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="RegionBrush" Color="{StaticResource SystemAltHighColor}" />
</ResourceDictionary>
<presets:PresetResources TargetTheme="Light" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="AppBackgroundBrush" Color="#FFF1F1F1" />
<SolidColorBrush x:Key="AppContentBackgroundBrush" Color="{StaticResource SystemAltHighColor}" />
<SolidColorBrush x:Key="CustomThemeBrush" Color="Red" />
</ui:ThemeDictionary>
<ui:ThemeDictionary Key="Dark">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:DefaultThemeResources Key="Dark" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="RegionBrush" Color="{StaticResource SystemAltHighColor}" />
</ResourceDictionary>
<presets:PresetResources TargetTheme="Dark" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="AppBackgroundBrush" Color="#FF232323" />
<SolidColorBrush x:Key="AppContentBackgroundBrush" Color="#FF282828" />
<SolidColorBrush x:Key="CustomThemeBrush" Color="Yellow" />
</ui:ThemeDictionary>
<ui:ThemeDictionary Key="HighContrast">
<SolidColorBrush x:Key="AppBackgroundBrush" Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}" />
<SolidColorBrush x:Key="AppContentBackgroundBrush" Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}" />
<SolidColorBrush x:Key="RegionBrush" Color="Transparent" />
<SolidColorBrush x:Key="CustomThemeBrush" Color="Blue" />
</ui:ThemeDictionary>
</ResourceDictionary.MergedDictionaries>-->
</ui:ThemeResources>
<ui:XamlControlsResources />
</ResourceDictionary.MergedDictionaries>
Expand Down
10 changes: 10 additions & 0 deletions ModernWpf.SampleApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
<ui:RadioMenuItem Header="Lavender" />
<ui:RadioMenuItem Header="Nighttime" />
</MenuItem>
<MenuItem
Header="Sizing"
MenuItem.Click="SizingMenuItem_Click">
<ui:RadioMenuItem
Header="Standard"
IsChecked="True" />
<ui:RadioMenuItem
Header="Compact"
Tag="Compact" />
</MenuItem>
</Menu>

<ListBox
Expand Down
14 changes: 14 additions & 0 deletions ModernWpf.SampleApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ private void PresetMenuItem_Click(object sender, RoutedEventArgs e)
PresetManager.Current.CurrentPreset = (string)menuItem.Header;
}
}

private void SizingMenuItem_Click(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is MenuItem menuItem)
{
bool compact = menuItem.Tag as string == "Compact";

var xcr = Application.Current.Resources.MergedDictionaries.OfType<XamlControlsResources>().FirstOrDefault();
if (xcr != null)
{
xcr.UseCompactResources = compact;
}
}
}
}

public class ControlPagesData : List<ControlPageInfo>
Expand Down
37 changes: 36 additions & 1 deletion ModernWpf/Controls/XamlControlsResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,42 @@ public class XamlControlsResources : ResourceDictionary
/// </summary>
public XamlControlsResources()
{
Source = PackUriHelper.GetAbsoluteUri("XamlControlsResources.xaml");
MergedDictionaries.Add(new ResourceDictionary { Source = PackUriHelper.GetAbsoluteUri("XamlControlsResources.xaml") });
}

public bool UseCompactResources
{
get => _useCompactResources;
set
{
if (_useCompactResources != value)
{
_useCompactResources = value;
if (_useCompactResources)
{
MergedDictionaries.Add(CompactResources);
}
else
{
MergedDictionaries.Remove(CompactResources);
};
}
}
}

internal static ResourceDictionary CompactResources
{
get
{
if (_compactResources == null)
{
_compactResources = new ResourceDictionary { Source = PackUriHelper.GetAbsoluteUri("DensityStyles/Compact.xaml") };
}
return _compactResources;
}
}

private static ResourceDictionary _compactResources;
private bool _useCompactResources;
}
}
1 change: 1 addition & 0 deletions ModernWpf/Styles/ListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:local="clr-namespace:ModernWpf.Controls"
xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives">

<sys:Double x:Key="ListViewItemMinHeight">40</sys:Double>
<sys:Double x:Key="GridViewColumnHeaderMinHeight">33</sys:Double>
<sys:Double x:Key="GridViewItemContainerMinHeight">32</sys:Double>

Expand Down
4 changes: 3 additions & 1 deletion ModernWpf/Styles/TreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ModernWpf.Controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives">

<sys:Double x:Key="TreeViewItemMinHeight">32</sys:Double>

<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Focusable" Value="False" />
Expand Down
6 changes: 0 additions & 6 deletions ModernWpf/ThemeResources/Dark.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<m:StaticResource x:Key="ContentControlThemeFontFamily" ResourceKey="{x:Static SystemFonts.MessageFontFamilyKey}" />
<FontFamily x:Key="SymbolThemeFontFamily">Segoe MDL2 Assets, /ModernWpf;component/Assets/#Segoe MDL2 Assets</FontFamily>
<sys:Double x:Key="ControlContentThemeFontSize">14</sys:Double>
<sys:Double x:Key="ContentControlFontSize">14</sys:Double>
<CornerRadius x:Key="ControlCornerRadius">2,2,2,2</CornerRadius>
<CornerRadius x:Key="OverlayCornerRadius">4,4,4,4</CornerRadius>

Expand Down Expand Up @@ -510,7 +508,6 @@
<sys:Double x:Key="ListViewItemReorderHintThemeOffset">10.0</sys:Double>
<sys:Double x:Key="ListViewItemSelectedBorderThemeThickness">4</sys:Double>
<sys:Double x:Key="ListViewItemMinWidth">88</sys:Double>
<sys:Double x:Key="ListViewItemMinHeight">40</sys:Double>
<m:StaticResource x:Key="ListViewItemBackground" ResourceKey="SystemControlTransparentBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
Expand Down Expand Up @@ -891,14 +888,11 @@
<m:StaticResource x:Key="TreeViewItemCheckBoxBorderSelected" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<m:StaticResource x:Key="TreeViewItemCheckGlyphSelected" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<Thickness x:Key="TreeViewItemBorderThemeThickness">1</Thickness>
<sys:Double x:Key="TreeViewItemMinHeight">32</sys:Double>

<sys:Double x:Key="TextControlThemeMinWidth">64</sys:Double>
<sys:Double x:Key="TextControlThemeMinHeight">32</sys:Double>
<Thickness x:Key="TextControlBorderThemeThickness">1</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">2</Thickness>
<Thickness x:Key="TextControlMarginThemeThickness">0,9.5,0,9.5</Thickness>
<Thickness x:Key="TextControlThemePadding">10,6,6,5</Thickness>
<Thickness x:Key="HelperButtonThemePadding">0,0,-2,0</Thickness>
<m:StaticResource x:Key="TextControlForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<m:StaticResource x:Key="TextControlForegroundPointerOver" ResourceKey="SystemControlForegroundBaseHighBrush" />
Expand Down
6 changes: 0 additions & 6 deletions ModernWpf/ThemeResources/HighContrast.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<m:StaticResource x:Key="ContentControlThemeFontFamily" ResourceKey="{x:Static SystemFonts.MessageFontFamilyKey}" />
<FontFamily x:Key="SymbolThemeFontFamily">Segoe MDL2 Assets, /ModernWpf;component/Assets/#Segoe MDL2 Assets</FontFamily>
<sys:Double x:Key="ControlContentThemeFontSize">14</sys:Double>
<sys:Double x:Key="ContentControlFontSize">14</sys:Double>
<CornerRadius x:Key="ControlCornerRadius">2,2,2,2</CornerRadius>
<CornerRadius x:Key="OverlayCornerRadius">4,4,4,4</CornerRadius>

Expand Down Expand Up @@ -510,7 +508,6 @@
<sys:Double x:Key="ListViewItemReorderHintThemeOffset">10.0</sys:Double>
<sys:Double x:Key="ListViewItemSelectedBorderThemeThickness">4</sys:Double>
<sys:Double x:Key="ListViewItemMinWidth">88</sys:Double>
<sys:Double x:Key="ListViewItemMinHeight">40</sys:Double>
<m:StaticResource x:Key="ListViewItemBackground" ResourceKey="SystemControlTransparentBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
Expand Down Expand Up @@ -891,14 +888,11 @@
<SolidColorBrush x:Key="TreeViewItemCheckBoxBorderSelected" Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}" />
<SolidColorBrush x:Key="TreeViewItemCheckGlyphSelected" Color="{DynamicResource {x:Static SystemColors.WindowTextColorKey}}" />
<Thickness x:Key="TreeViewItemBorderThemeThickness">1</Thickness>
<sys:Double x:Key="TreeViewItemMinHeight">32</sys:Double>

<sys:Double x:Key="TextControlThemeMinWidth">64</sys:Double>
<sys:Double x:Key="TextControlThemeMinHeight">32</sys:Double>
<Thickness x:Key="TextControlBorderThemeThickness">1</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">2</Thickness>
<Thickness x:Key="TextControlMarginThemeThickness">0,9.5,0,9.5</Thickness>
<Thickness x:Key="TextControlThemePadding">10,6,6,5</Thickness>
<Thickness x:Key="HelperButtonThemePadding">0,0,-2,0</Thickness>
<m:StaticResource x:Key="TextControlForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<m:StaticResource x:Key="TextControlForegroundPointerOver" ResourceKey="SystemControlForegroundBaseHighBrush" />
Expand Down
6 changes: 0 additions & 6 deletions ModernWpf/ThemeResources/Light.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<m:StaticResource x:Key="ContentControlThemeFontFamily" ResourceKey="{x:Static SystemFonts.MessageFontFamilyKey}" />
<FontFamily x:Key="SymbolThemeFontFamily">Segoe MDL2 Assets, /ModernWpf;component/Assets/#Segoe MDL2 Assets</FontFamily>
<sys:Double x:Key="ControlContentThemeFontSize">14</sys:Double>
<sys:Double x:Key="ContentControlFontSize">14</sys:Double>
<CornerRadius x:Key="ControlCornerRadius">2,2,2,2</CornerRadius>
<CornerRadius x:Key="OverlayCornerRadius">4,4,4,4</CornerRadius>

Expand Down Expand Up @@ -510,7 +508,6 @@
<sys:Double x:Key="ListViewItemReorderHintThemeOffset">10.0</sys:Double>
<sys:Double x:Key="ListViewItemSelectedBorderThemeThickness">4</sys:Double>
<sys:Double x:Key="ListViewItemMinWidth">88</sys:Double>
<sys:Double x:Key="ListViewItemMinHeight">40</sys:Double>
<m:StaticResource x:Key="ListViewItemBackground" ResourceKey="SystemControlTransparentBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
<m:StaticResource x:Key="ListViewItemBackgroundPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
Expand Down Expand Up @@ -891,14 +888,11 @@
<m:StaticResource x:Key="TreeViewItemCheckBoxBorderSelected" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<m:StaticResource x:Key="TreeViewItemCheckGlyphSelected" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<Thickness x:Key="TreeViewItemBorderThemeThickness">1</Thickness>
<sys:Double x:Key="TreeViewItemMinHeight">32</sys:Double>

<sys:Double x:Key="TextControlThemeMinWidth">64</sys:Double>
<sys:Double x:Key="TextControlThemeMinHeight">32</sys:Double>
<Thickness x:Key="TextControlBorderThemeThickness">1</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">2</Thickness>
<Thickness x:Key="TextControlMarginThemeThickness">0,9.5,0,9.5</Thickness>
<Thickness x:Key="TextControlThemePadding">10,6,6,5</Thickness>
<Thickness x:Key="HelperButtonThemePadding">0,0,-2,0</Thickness>
<m:StaticResource x:Key="TextControlForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<m:StaticResource x:Key="TextControlForegroundPointerOver" ResourceKey="SystemControlForegroundBaseHighBrush" />
Expand Down
8 changes: 7 additions & 1 deletion ModernWpf/XamlControlsResources.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives">
xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives"
xmlns:sys="clr-namespace:System;assembly=mscorlib">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Calendar.xaml" />
Expand Down Expand Up @@ -33,6 +34,11 @@
<ResourceDictionary Source="Styles/Window.xaml" />
</ResourceDictionary.MergedDictionaries>

<sys:Double x:Key="ControlContentThemeFontSize">14</sys:Double>
<sys:Double x:Key="ContentControlFontSize">14</sys:Double>
<sys:Double x:Key="TextControlThemeMinHeight">32</sys:Double>
<Thickness x:Key="TextControlThemePadding">10,6,6,5</Thickness>

<Style x:Key="EmptyFocusVisual">
<Setter Property="primitives:FocusVisualHelper.IsSystemFocusVisual" Value="True" />
</Style>
Expand Down

0 comments on commit 0e204ab

Please sign in to comment.