2015-08-15 53 views
0

我想爲我的應用程序創建一個自定義標題欄。我不知道如何添加窗口最大化或最小化圖標到按鈕。我希望我的圖標Ø類似於此WPF如何獲得最大化/最小化按鈕圖標 - 自定義標題欄

Maximize/Minimize example

這裏是我的我的按鈕XAML

  <Button Command="{x:Static SystemCommands.MaximizeWindowCommand}" Content="+" Canvas.Left="1020" Height="30" Width="30"> 
      <Button.Style> 
       <Style TargetType="{x:Type Button}"> 
        <Setter Property="Background" Value="Black"/> 
        <Setter Property="TextBlock.Foreground" Value="White"/> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type Button}"> 
           <Border Background="{TemplateBinding Background}"> 
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> 
           </Border> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
        <Style.Triggers> 
         <Trigger Property="IsMouseOver" Value="True"> 
          <Setter Property="Background" Value="#403c47"/> 
         </Trigger> 
        </Style.Triggers> 
       </Style> 
      </Button.Style> 
     </Button> 
     <Button Command="{x:Static SystemCommands.MinimizeWindowCommand}" Content="" Canvas.Left="990" Height="30" Width="30" > 
      <Button.Style> 
       <Style TargetType="{x:Type Button}"> 
        <Setter Property="Background" Value="Black"/> 
        <Setter Property="TextBlock.Foreground" Value="White"/> 
        <Setter Property="FontSize" Value="24"/> 
        <Setter Property="TextBlock.LineHeight" Value="5"/> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type Button}"> 
           <Border Background="{TemplateBinding Background}"> 
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> 
           </Border> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
        <Style.Triggers> 
         <Trigger Property="IsMouseOver" Value="True"> 
          <Setter Property="Background" Value="#403c47"/> 
         </Trigger> 
        </Style.Triggers> 
       </Style> 
      </Button.Style> 
     </Button> 

任何援助表示讚賞:)

+0

只是得到一些不錯的圖標/圖片,並使用圖像元素爲您的按鈕內容 – Carsten

+0

我不想使用圖標/圖片時,已經有一個內置到窗口。 –

+0

爲什麼你不只是使用一個窗口呢? – Noctis

回答

5

這個代碼摘錄我已經使用。 (在我的情況是一個可重複使用的窗口類擴展,過長完全後)

XAML 2按鈕最小化和最大化

<Grid Margin="1,0,1,0"> 
    <Button x:Name="Restore" Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}" Visibility="Collapsed" Style="{StaticResource WindowButtonStyle}"> 
     <Grid Width="30" Height="25" UseLayoutRounding="True" RenderTransform="1,0,0,1,.5,.5"> 
      <Path Data="M2,0 L8,0 L8,6 M0,3 L6,3 M0,2 L6,2 L6,8 L0,8 Z" Width="8" Height="8" VerticalAlignment="Center" HorizontalAlignment="Center" 
       Stroke="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}, Mode=FindAncestor}}" StrokeThickness="1" /> 
     </Grid> 
    </Button> 
    <Button x:Name="Maximize" Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}" Style="{StaticResource WindowButtonStyle}"> 
     <Grid Width="31" Height="25"> 
      <Path Data="M0,1 L9,1 L9,8 L0,8 Z" Width="9" Height="8" VerticalAlignment="Center" HorizontalAlignment="Center" 
       Stroke="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}, Mode=FindAncestor}}" StrokeThickness="2" /> 
     </Grid> 
    </Button> 
</Grid> 

觸發隱藏最小化/最大化按鈕時被最大化/最小化窗口

<ControlTemplate.Triggers> 
    <Trigger Property="WindowState" Value="Maximized"> 
     <Setter TargetName="Maximize" Property="Visibility" Value="Collapsed" /> 
     <Setter TargetName="Restore" Property="Visibility" Value="Visible" /> 
    </Trigger> 
    <Trigger Property="WindowState" Value="Normal"> 
     <Setter TargetName="Maximize" Property="Visibility" Value="Visible" /> 
     <Setter TargetName="Restore" Property="Visibility" Value="Collapsed" /> 
    </Trigger> 
    ..... 
</ControlTemplate.Triggers> 

enter image description here

希望能適應您的需求。

+0

爲什麼還原符號看起來模糊? –

+1

@Xilmiki你可以添加最小化按鈕路徑數據以及? –

1

另一種解決方案是使用Webdings字體,它分別在0,1和2上最小化,最大化和恢復字形。

也有這些例如Unicode字符。 但它們相對較新,目前似乎在所有語言環境中都不能正常工作。

相關問題