|
<Window x:Class="CustomCaption.MainWindow" |
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|
xmlns:local="clr-namespace:CustomCaption" |
|
mc:Ignorable="d" |
|
Title="MainWindow" x:Name="MainWindow1" |
|
Height="240" Width="320" |
|
ResizeMode="CanResize" |
|
Icon="small.ico"> |
|
|
|
<Window.Resources> |
|
<!-- Window用カラー --> |
|
<SolidColorBrush x:Key="MainWindowBackgroundKey" Color="#FFF"/> |
|
<SolidColorBrush x:Key="MainWindowForegroundKey" Color="#111"/> |
|
<SolidColorBrush x:Key="MainWindowBorderBrushKey" Color="Aquamarine"/> |
|
|
|
<!-- キャプションボタンのスタイル --> |
|
<Style x:Key="CustomCaptionButtonKey" TargetType="{x:Type Button}" |
|
BasedOn="{StaticResource CustomCaptionButtonKey}"> |
|
<Setter Property="Background" Value="{x:Null}"/> |
|
<Setter Property="Foreground" Value="{StaticResource MainWindowForegroundKey}"/> |
|
<Setter Property="Height" Value="30"/> |
|
<Setter Property="Width" Value="40"/> |
|
<Setter Property="FontSize" Value="14"/> |
|
</Style> |
|
|
|
<!-- Converter --> |
|
<local:BorderThicknessByWindowStateConverter x:Key="BorderThicknessByWindowStateConverterKey"/> |
|
<local:WindowBorderBrushConverter x:Key="WindowBorderBrushConverterKey"/> |
|
<local:CaptionBarBackgroundConverter x:Key="CaptionBarBackgroundConverterKey"/> |
|
<local:MaximizeCaptionButtonContentConverter x:Key="MaximizeCaptionButtonContentConverterKey"/> |
|
<local:MaximizeCaptionButtonTooltipConverter x:Key="MaximizeCaptionButtonTooltipConverter"/> |
|
<local:MaximizeCaptionButtonEnableConverter x:Key="MaximizeCaptionButtonEnableConverterKey"/> |
|
<local:ResizeCaptionButtonVisibilityConverter x:Key="ResizeCaptionButtonVisibilityConverterKey"/> |
|
</Window.Resources> |
|
|
|
<Window.CommandBindings> |
|
<CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" |
|
Executed="CloseWindow"/> |
|
<CommandBinding Command="{x:Static SystemCommands.MaximizeWindowCommand}" |
|
Executed="MaximizeOrRestoreWindow"/> |
|
<CommandBinding Command="{x:Static SystemCommands.MinimizeWindowCommand}" |
|
Executed="MinimizeWindow"/> |
|
</Window.CommandBindings> |
|
|
|
<WindowChrome.WindowChrome> |
|
<WindowChrome CaptionHeight="30" |
|
ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" |
|
GlassFrameThickness="0,0,0,1"/> |
|
</WindowChrome.WindowChrome> |
|
|
|
<Border BorderThickness="{Binding WindowState, Converter={StaticResource BorderThicknessByWindowStateConverterKey}, |
|
ElementName=MainWindow1}" |
|
BorderBrush="{Binding IsActive, Converter={StaticResource WindowBorderBrushConverterKey}, |
|
ConverterParameter={StaticResource MainWindowBorderBrushKey}, ElementName=MainWindow1}"> |
|
<Grid> |
|
<!-- 上からタイトルバー、コンテンツ --> |
|
<Grid.RowDefinitions> |
|
<RowDefinition Height="30"/> |
|
<RowDefinition Height="*"/> |
|
</Grid.RowDefinitions> |
|
|
|
<!-- タイトルバー --> |
|
<Grid Grid.Row="0" |
|
Background="{Binding IsActive, Converter={StaticResource CaptionBarBackgroundConverterKey}, |
|
ConverterParameter={StaticResource MainWindowBorderBrushKey}, ElementName=MainWindow1}"> |
|
|
|
<!-- 左からアイコン、タイトル、コマンドボタン --> |
|
<Grid.ColumnDefinitions> |
|
<ColumnDefinition Width="Auto"/> |
|
<ColumnDefinition Width="*"/> |
|
<ColumnDefinition Width="Auto"/> |
|
</Grid.ColumnDefinitions> |
|
|
|
<!-- アイコンを表示します --> |
|
<Image Grid.Column="0" |
|
Margin="5" |
|
Source="{Binding Icon, ElementName=MainWindow1}"/> |
|
|
|
<!-- ウィンドウタイトルを表示します --> |
|
<Grid Grid.Column="1"> |
|
<StackPanel HorizontalAlignment="Left" |
|
VerticalAlignment="Center"> |
|
<TextBlock Text="{Binding Title, ElementName=MainWindow1}" |
|
Foreground="Black" |
|
Padding="5,0"/> |
|
</StackPanel> |
|
</Grid> |
|
|
|
<!-- 最小化、最大化、閉じるボタンを設置します --> |
|
<Grid Grid.Column="2"> |
|
<StackPanel Orientation="Horizontal" |
|
HorizontalAlignment="Right" |
|
VerticalAlignment="Center"> |
|
<!-- 最小化ボタン --> |
|
<Button Content="0" |
|
Style="{StaticResource CustomCaptionButtonKey}" |
|
Visibility="{Binding ResizeMode, Converter={StaticResource ResizeCaptionButtonVisibilityConverterKey}, ElementName=MainWindow1}" |
|
ToolTip="最小化" |
|
Command="{x:Static SystemCommands.MinimizeWindowCommand}" /> |
|
<!-- 最大化ボタン --> |
|
<Button Content="{Binding WindowState,Converter={StaticResource MaximizeCaptionButtonContentConverterKey}, ElementName=MainWindow1}" |
|
Style="{StaticResource CustomCaptionButtonKey}" |
|
IsEnabled="{Binding ResizeMode, Converter={StaticResource MaximizeCaptionButtonEnableConverterKey}, ElementName=MainWindow1}" |
|
Visibility="{Binding ResizeMode, Converter={StaticResource ResizeCaptionButtonVisibilityConverterKey}, ElementName=MainWindow1}" |
|
ToolTip="{Binding WindowState, Converter={StaticResource MaximizeCaptionButtonTooltipConverter}, ElementName=MainWindow1}" |
|
Command="{x:Static SystemCommands.MaximizeWindowCommand}"/> |
|
<!-- 閉じるボタン --> |
|
<Button Content="r" |
|
Style="{StaticResource CustomCaptionButtonKey}" |
|
ToolTip="閉じる" |
|
Command="{x:Static SystemCommands.CloseWindowCommand}"/> |
|
</StackPanel> |
|
</Grid> |
|
|
|
</Grid> |
|
|
|
<!-- コンテンツ --> |
|
<StackPanel Grid.Row="1" |
|
Margin="30" |
|
TextBlock.FontSize="16"> |
|
<TextBlock Text="リサイズモード"/> |
|
<ComboBox x:Name="Mode" |
|
SelectionChanged="ComboBox_SelectionChanged" |
|
SelectedIndex="2"> |
|
<ListBoxItem Content="NoResize"/> |
|
<ListBoxItem Content="CanMinimize"/> |
|
<ListBoxItem Content="CanResize"/> |
|
<ListBoxItem Content="CanResizeWithGrip"/> |
|
</ComboBox> |
|
</StackPanel> |
|
</Grid> |
|
</Border> |
|
</Window> |