Skip to content

Commit

Permalink
improved support for HighDPI screens
Browse files Browse the repository at this point in the history
* new DpiAwareWindow base class with support for PerMonitor DPI awareness availabe in Windows 8.1
* ModernWindow styles updated for better viewing on high dpi screens
* default ModernButton size increased
* BBCodeBlock.BBCode now default Content property
* ModernWindow resizegrip now functions properly
  • Loading branch information
kozw_cp authored and kozw_cp committed Aug 9, 2014
1 parent 804de78 commit 05da91d
Show file tree
Hide file tree
Showing 30 changed files with 1,399 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<Setter Property="BorderThickness" Value="2" />
</Style>
</StackPanel.Resources>
<mui:ModernButton EllipseDiameter="16" IconWidth="8" IconHeight="8"/>
<mui:ModernButton EllipseDiameter="20" IconWidth="12" IconHeight="8"/>
<mui:ModernButton />
<mui:ModernButton EllipseDiameter="24" IconWidth="14" IconHeight="14" />
<mui:ModernButton EllipseDiameter="26" IconWidth="14" IconHeight="14" />
<mui:ModernButton EllipseDiameter="32" IconWidth="20" IconHeight="20" />
<mui:ModernButton EllipseDiameter="48" EllipseStrokeThickness="2" IconWidth="30" IconHeight="30" />
<mui:ModernButton EllipseDiameter="64" EllipseStrokeThickness="2" IconWidth="42" IconHeight="42" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
<TextBlock Text="MODERNWINDOW" Style="{StaticResource Heading2}" Margin="0,0,0,8" />
<mui:BBCodeBlock BBCode="Demonstrating the use of custom styles to adapt ModernWindow to your needs. Additional ModernWindow styles are defined in [b]Assets\ModernWindowEx.xaml[/b]" Margin="0,0,0,16" />

<CheckBox x:Name="title" Content="title" IsChecked="True" Margin="0,0,0,2" />
<CheckBox x:Name="logo" Content="logo" IsChecked="True" Margin="0,0,0,2"/>

<StackPanel Margin="0,0,0,8">
<RadioButton x:Name="noresize" Content="no resize" Margin="0,0,0,2" />
<RadioButton x:Name="canminimize" Content="can minimize" Margin="0,0,0,2"/>
<RadioButton x:Name="canresize" Content="can resize" Margin="0,0,0,2"/>
<RadioButton x:Name="canresizewithgrip" Content="can resize with grip" IsChecked="True" Margin="0,0,0,2"/>
</StackPanel>

<Button Content="empty window style" Margin="0,0,0,8" HorizontalAlignment="Left" Click="EmptyWindow_Click"/>

</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,29 @@ private void EmptyWindow_Click(object sender, RoutedEventArgs e)

var wnd = new ModernWindow {
Style = (Style)App.Current.Resources["EmptyWindow"],
Content = new LoremIpsum {
Margin = new Thickness(32)
},
Title = "ModernWindow",
IsTitleVisible = true == this.title.IsChecked,
Content = new LoremIpsum(),
Width = 480,
Height = 480
};

if (true == this.logo.IsChecked) {
wnd.LogoData = PathGeometry.Parse("F1 M 24.9015,43.0378L 25.0963,43.4298C 26.1685,49.5853 31.5377,54.2651 38,54.2651C 44.4623,54.2651 49.8315,49.5854 50.9037,43.4299L 51.0985,43.0379C 51.0985,40.7643 52.6921,39.2955 54.9656,39.2955C 56.9428,39.2955 58.1863,41.1792 58.5833,43.0379C 57.6384,52.7654 47.9756,61.75 38,61.75C 28.0244,61.75 18.3616,52.7654 17.4167,43.0378C 17.8137,41.1792 19.0572,39.2954 21.0344,39.2954C 23.3079,39.2954 24.9015,40.7643 24.9015,43.0378 Z M 26.7727,20.5833C 29.8731,20.5833 32.3864,23.0966 32.3864,26.197C 32.3864,29.2973 29.8731,31.8106 26.7727,31.8106C 23.6724,31.8106 21.1591,29.2973 21.1591,26.197C 21.1591,23.0966 23.6724,20.5833 26.7727,20.5833 Z M 49.2273,20.5833C 52.3276,20.5833 54.8409,23.0966 54.8409,26.197C 54.8409,29.2973 52.3276,31.8106 49.2273,31.8106C 46.127,31.8106 43.6136,29.2973 43.6136,26.197C 43.6136,23.0966 46.127,20.5833 49.2273,20.5833 Z");
}
if (true == this.noresize.IsChecked) {
wnd.ResizeMode = ResizeMode.NoResize;
}
else if (true == this.canminimize.IsChecked) {
wnd.ResizeMode = ResizeMode.CanMinimize;
}
else if (true == this.canresize.IsChecked) {
wnd.ResizeMode = ResizeMode.CanResize;
}
else if (true == this.canresizewithgrip.IsChecked) {
wnd.ResizeMode = ResizeMode.CanResizeWithGrip;
}

wnd.Show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
<Compile Include="Content\ModernFrame\Sample.xaml.cs">
<DependentUpon>Sample.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\DpiAwareness.xaml.cs">
<DependentUpon>DpiAwareness.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\DpiAwarenessViewModel.cs" />
<Compile Include="SampleFormViewModel.cs" />
<Compile Include="FlickrImageLoader.cs" />
<Compile Include="LoremIpsumLoader.cs" />
Expand Down Expand Up @@ -359,6 +363,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\DpiAwareness.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\Navigation.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
Title="mui" IsTitleVisible="True"
Title="Modern UI for WPF Demo" IsTitleVisible="True"
LogoData="F1 M 24.9015,43.0378L 25.0963,43.4298C 26.1685,49.5853 31.5377,54.2651 38,54.2651C 44.4623,54.2651 49.8315,49.5854 50.9037,43.4299L 51.0985,43.0379C 51.0985,40.7643 52.6921,39.2955 54.9656,39.2955C 56.9428,39.2955 58.1863,41.1792 58.5833,43.0379C 57.6384,52.7654 47.9756,61.75 38,61.75C 28.0244,61.75 18.3616,52.7654 17.4167,43.0378C 17.8137,41.1792 19.0572,39.2954 21.0344,39.2954C 23.3079,39.2954 24.9015,40.7643 24.9015,43.0378 Z M 26.7727,20.5833C 29.8731,20.5833 32.3864,23.0966 32.3864,26.197C 32.3864,29.2973 29.8731,31.8106 26.7727,31.8106C 23.6724,31.8106 21.1591,29.2973 21.1591,26.197C 21.1591,23.0966 23.6724,20.5833 26.7727,20.5833 Z M 49.2273,20.5833C 52.3276,20.5833 54.8409,23.0966 54.8409,26.197C 54.8409,29.2973 52.3276,31.8106 49.2273,31.8106C 46.127,31.8106 43.6136,29.2973 43.6136,26.197C 43.6136,23.0966 46.127,20.5833 49.2273,20.5833 Z"
ContentSource="/Pages/Introduction.xaml">

Expand Down Expand Up @@ -33,6 +33,7 @@
</mui:LinkGroup>
<mui:LinkGroup DisplayName="Advanced">
<mui:LinkGroup.Links>
<mui:Link DisplayName="DPI awereness" Source="/Pages/DpiAwareness.xaml" />
<mui:Link DisplayName="Navigation" Source="/Pages/Navigation.xaml" />
<mui:Link DisplayName="Content Loader" Source="/Pages/ContentLoader.xaml" />
</mui:LinkGroup.Links>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<UserControl x:Class="FirstFloor.ModernUI.App.Pages.DpiAwareness"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Style="{StaticResource ContentRoot}">
<ScrollViewer>
<StackPanel >
<TextBlock Text="DPI AWARENESS" Style="{StaticResource Heading1}" Margin="0,0,0,8"/>
<mui:BBCodeBlock Margin="0,0,0,32" xml:space="preserve">Windows 8.1 gives developers new functionality to create desktop applications that are per-monitor DPI-aware. MUI automatically enables per-monitor DPI awereness when supported by the host OS. When enabled a window is scaled across monitors of different DPIs.

MUI's implementation of per-monitor DPI awareness is largely based on the MSDN article [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ee308410(v=vs.85).aspx]Developing a Per-Monitor DPI-Aware WPF Application[/url].</mui:BBCodeBlock>

<TextBlock Text="DPI INFORMATION" Style="{StaticResource Heading2}"/>
<mui:BBCodeBlock BBCode="{Binding DpiAwareMessage}" Margin="0,0,0,16" />
<Grid>
<Grid.Resources>
<Style x:Key="RightAlign" TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Margin" Value="16,0,0,4" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock Text="WPF rendering DPI:" />
<TextBlock Grid.Column="1" Text="{Binding WpfDpi}" Style="{StaticResource RightAlign}" />
<TextBlock Grid.Row="1" Text="Current monitor DPI:" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding MonitorDpi}" Style="{StaticResource RightAlign}" />
<TextBlock Grid.Row="2" Text="Layout scale:" />
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding LayoutScale}" Style="{StaticResource RightAlign}" />
<TextBlock Grid.Row="3" Text="Window size:" />
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding WindowSize}" Style="{StaticResource RightAlign}" />
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FirstFloor.ModernUI.App.Pages
{
/// <summary>
/// Interaction logic for DpiAwareness.xaml
/// </summary>
public partial class DpiAwareness : UserControl
{
public DpiAwareness()
{
InitializeComponent();

this.DataContext = new DpiAwarenessViewModel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace FirstFloor.ModernUI.App.Pages
{
public class DpiAwarenessViewModel
: NotifyPropertyChanged
{
private DpiAwareWindow wnd;

/// <summary>
/// Initializes a new instance of the <see cref="DpiAwarenessViewModel" /> class.
/// </summary>
public DpiAwarenessViewModel()
{
this.wnd = (DpiAwareWindow)App.Current.MainWindow;
this.wnd.DpiChanged += OnWndDpiChanged;
this.wnd.SizeChanged += OnWndSizeChanged;
}

private void OnWndDpiChanged(object sender, EventArgs e)
{
OnPropertyChanged(null); // refresh all properties
}

private void OnWndSizeChanged(object sender, SizeChangedEventArgs e)
{
OnPropertyChanged(null); // refresh all properties
}

public string DpiAwareMessage
{
get
{
return string.Format(CultureInfo.InvariantCulture, "The DPI awareness of this process is [b]{0}[/b]", ModernUIHelper.GetDpiAwereness());
}
}

public string WpfDpi
{
get
{
var info = this.wnd.DpiInformation;
return string.Format(CultureInfo.InvariantCulture, "{0} x {1}", info.WpfDpiX, info.WpfDpiY);
}
}

public string MonitorDpi
{
get
{
var info = this.wnd.DpiInformation;
if (info.MonitorDpiX.HasValue) {
return string.Format(CultureInfo.InvariantCulture, "{0} x {1}", info.MonitorDpiX, info.MonitorDpiY);
}
return "n/a";
}
}

public string LayoutScale
{
get
{
var info = this.wnd.DpiInformation;
return string.Format(CultureInfo.InvariantCulture, "{0} x {1}", info.ScaleX, info.ScaleY);
}
}

public string WindowSize
{
get
{
var info = this.wnd.DpiInformation;
var width = this.wnd.ActualWidth * info.WpfDpiX / 96D;
var height = this.wnd.ActualHeight * info.WpfDpiY / 96D;

return string.Format(CultureInfo.InvariantCulture, "{0} x {1}", width, height);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand Down Expand Up @@ -30,6 +31,9 @@

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]

// required for PerMonitor DPI support to work
[assembly:DisableDpiAwareness]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,24 @@
<Compile Include="..\FirstFloor.ModernUI\Presentation\RelayCommand.cs">
<Link>Presentation\RelayCommand.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\ProcessDpiAwareness.cs">
<Link>ProcessDpiAwareness.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Win32\MonitorDpiType.cs">
<Link>Win32\MonitorDpiType.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Win32\NativeMethods.cs">
<Link>Win32\NativeMethods.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Win32\OSVersionHelper.cs">
<Link>Win32\OSVersionHelper.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Win32\RECT.cs">
<Link>Win32\RECT.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Windows\CommandDictionary.cs">
<Link>Windows\CommandDictionary.cs</Link>
</Compile>
Expand Down Expand Up @@ -142,6 +157,12 @@
<Compile Include="..\FirstFloor.ModernUI\Windows\Controls\DataGridTextColumn.cs">
<Link>Windows\Controls\DataGridTextColumn.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Windows\Controls\DpiAwareWindow.cs">
<Link>Windows\Controls\DpiAwareWindow.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Windows\Controls\DpiInformation.cs">
<Link>Windows\Controls\DpiInformation.cs</Link>
</Compile>
<Compile Include="..\FirstFloor.ModernUI\Windows\Controls\ModernButton.cs">
<Link>Windows\Controls\ModernButton.cs</Link>
</Compile>
Expand Down
Loading

0 comments on commit 05da91d

Please sign in to comment.