ChromeWindow.xaml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <Window x:Class="CustomControls.ChromeWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. WindowStyle="SingleBorderWindow" ResizeMode="CanResize" UseLayoutRounding="True" >
  5. <Window.Resources>
  6. <ResourceDictionary>
  7. <SolidColorBrush x:Key="Border.Foreground" Color="DarkGray"/>
  8. <SolidColorBrush x:Key="Title.Background" Color="#f3f3f3"/>
  9. <SolidColorBrush x:Key="Title.Foreground" Color="Black"/>
  10. <SolidColorBrush x:Key="Button.Static.Foreground" Color="Black"/>
  11. <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#e9e9e9"/>
  12. <SolidColorBrush x:Key="Button.MouseOver.Foreground" Color="Black"/>
  13. <SolidColorBrush x:Key="CloseButton.MouseOver.Background" Color="#c42b1c"/>
  14. <SolidColorBrush x:Key="CloseButton.MouseOver.Foreground" Color="White"/>
  15. <!--Base style for title bar buttons-->
  16. <Style x:Key="CaptionButtonStyle" TargetType="Button">
  17. <Setter Property="Background" Value="{DynamicResource Button.MouseOver.Background}"/>
  18. <Setter Property="Foreground" Value="{DynamicResource Button.MouseOver.Foreground}"/>
  19. <Setter Property="Template">
  20. <Setter.Value>
  21. <ControlTemplate TargetType="Button">
  22. <Grid x:Name="LayoutRoot" Background="Transparent" Width="44" Height="30">
  23. <Path x:Name="path" Width="10" Height="10" Data="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"
  24. Stroke="{DynamicResource Button.Static.Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
  25. </Grid>
  26. <ControlTemplate.Triggers>
  27. <Trigger Property="IsMouseOver" Value="True">
  28. <Setter TargetName="LayoutRoot" Property="Background" Value="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"/>
  29. <Setter TargetName="path" Property="Stroke" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/>
  30. </Trigger>
  31. <Trigger Property="IsEnabled" Value="False">
  32. <Setter TargetName="path" Property="Opacity" Value="0.4"/>
  33. </Trigger>
  34. </ControlTemplate.Triggers>
  35. </ControlTemplate>
  36. </Setter.Value>
  37. </Setter>
  38. </Style>
  39. <!--Minimize-->
  40. <Style x:Key="MinimizeButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
  41. <Setter Property="Content" Value="M0,5.5 L10,5.5"/>
  42. </Style>
  43. <!--Maximize-->
  44. <Style x:Key="MaximizeButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
  45. <Setter Property="Content" Value="M0.5,0.5 L9.5,0.5 L9.5,9.5 L0.5,9.5 z"/>
  46. </Style>
  47. <!--Restore-->
  48. <Style x:Key="RestoreButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
  49. <Setter Property="Content" Value="M0.5,2.5 L7.5,2.5 L7.5,9.5 L0.5,9.5 z M2.5,0.5 L9.5,0.5 L9.5,7.5"/>
  50. </Style>
  51. <!--Close-->
  52. <Style x:Key="CloseButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}">
  53. <Setter Property="Content" Value="M0.5,0.5 L9.5,9.5 M0.5,9.5 L9.5,0.5"/>
  54. <Setter Property="Background" Value="{DynamicResource CloseButton.MouseOver.Background}"/>
  55. <Setter Property="Foreground" Value="{DynamicResource CloseButton.MouseOver.Foreground}"/>
  56. </Style>
  57. </ResourceDictionary>
  58. </Window.Resources>
  59. <!--Title bar button commands-->
  60. <Window.CommandBindings>
  61. <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Close" />
  62. <CommandBinding Command="{x:Static SystemCommands.MaximizeWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Maximize" />
  63. <CommandBinding Command="{x:Static SystemCommands.MinimizeWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Minimize" />
  64. <CommandBinding Command="{x:Static SystemCommands.RestoreWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Restore" />
  65. </Window.CommandBindings>
  66. <Grid x:Name="parentContainer">
  67. <Grid.RowDefinitions>
  68. <RowDefinition Height="Auto"/>
  69. <RowDefinition Height="*"/>
  70. </Grid.RowDefinitions>
  71. <!--App content-->
  72. <ContentControl Grid.Row="1" x:Name="AppArea"/>
  73. <!--Window chrome-->
  74. <Grid x:Name="TitleArea" Grid.Row="0" Height="30" Background="{DynamicResource Title.Background}" MouseLeftButtonDown="TitleArea_MouseDown" MouseMove="TitleArea_MouseMove" MouseUp="TitleArea_MouseUp">
  75. <DockPanel x:Name="TitleDock" VerticalAlignment="Center" LastChildFill="True">
  76. <!--App icon-->
  77. <Image x:Name="TitleIcon" Source="{Binding Icon, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Margin="8,0,0,0" MaxWidth="16" MaxHeight="16" DockPanel.Dock="Left" VerticalAlignment="Center" MouseDown="TitleIcon_MouseDown" />
  78. <TextBlock x:Name="TitleText" Text="{Binding Title, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" TextTrimming="CharacterEllipsis" Margin="8,0,0,0" VerticalAlignment="Stretch" Foreground="{DynamicResource Title.Foreground}" />
  79. </DockPanel>
  80. <!--Caption buttons-->
  81. <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
  82. <Button x:Name="MinimizeButton" Style="{StaticResource MinimizeButtonStyle}" Command="{x:Static SystemCommands.MinimizeWindowCommand}"/>
  83. <Button x:Name="RestoreButton" Visibility="Collapsed" Style="{StaticResource RestoreButtonStyle}" Command="{x:Static SystemCommands.RestoreWindowCommand}"/>
  84. <Button x:Name="MaximizeButton" Visibility="Visible" Style="{StaticResource MaximizeButtonStyle}" Command="{x:Static SystemCommands.MaximizeWindowCommand}"/>
  85. <Button x:Name="CloseButton" Style="{StaticResource CloseButtonStyle}" Command="{x:Static SystemCommands.CloseWindowCommand}"/>
  86. </StackPanel>
  87. </Grid>
  88. <Border x:Name="WindowBorder" BorderThickness="1" BorderBrush="{DynamicResource Border.Foreground}" Grid.RowSpan="2"/>
  89. <Border x:Name="ResizingBorder" BorderThickness="4" BorderBrush="Transparent" Grid.RowSpan="2" MouseDown="Border_MouseDown" MouseMove="Border_MouseMove" MouseLeave="Border_MouseLeave"/>
  90. </Grid>
  91. </Window>