2012-02-23 57 views
2

有沒有簡單的方法來製作一個完全正方形的Button?通常,Button有點圓,所以我該如何實現?你如何製作一個完全方形的按鈕?

+1

檢查出來:HTTP://www.codeproject .COM /用品/ 32257/A-風格換圓玻WPF的按鈕。這就像我在谷歌找到的第一個結果。 :P – 2012-02-23 08:15:16

+1

未來,如果您想知道如何更改WPF中某個控件的某個特定可視組件,或者只是想知道它是如何構建的,那麼使用[Snoop](http:// snoopwpf.codeplex.com/)。 – 2012-02-23 08:23:52

+0

我會深入研究的,謝謝! – 2012-02-23 08:50:41

回答

4

如果你的意思是有寬度=身高然後看看WPF dynamic layout: how to enforce square proportions (width equals height)?

如果你的意思是有方角,然後設置邊框的CornerRadius零:

<ControlTemplate x:Key="SquareButton" TargetType="{x:Type Button}"> 
<Border CornerRadius="0"/> 
</ControlTemplate> 

然後該按鈕使用的是模板:

<Button Template="{StaticResource SquareButton}"/> 
+0

他想盡我所能地擺脫四捨五入 – 2012-02-23 08:18:50

+0

這是正確的,但仍然保持按鈕效果。 Ivan CrojachKaračić我已經使用了您的解決方案,但我也想保持按鈕效果。我真的必須使用混合來做到這一點,或者你可以做到這一切我XAML? – 2012-02-23 08:55:32

+0

你只需要更新你的按鈕的控制模板,這就是爲什麼我只顯示相關位。這只是一個編輯XAML的案例 – kaj 2012-02-23 09:01:41

5

只需創建一個自定義按鈕樣式...像這樣的東西

<Style x:Key="ButtonStyle" TargetType="Button"> 
    <Setter Property="FontFamily" 
      Value="Arial Narrow" /> 
    <Setter Property="FontSize" 
      Value="13" /> 
    <Setter Property="Width" Value="50"/> 
    <Setter Property="Height" Value="20"/> 
    <Setter Property="Margin" Value="3"/> 
    <Setter Property="Cursor" Value="Hand"/> 
    <Setter Property="BorderBrush" Value="#FF1733D2"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="HorizontalAlignment" Value="Left"/> 
    <Setter Property="VerticalAlignment" Value="Top"/> 
    <Setter Property="Foreground" Value="White"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Button"> 
       <Border x:Name="Border" Background="#FF1733D2"> 
        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" /> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

如果您對按鈕...編輯風格融爲一體點擊 - >編輯當前...,擺脫圓角半徑的我覺得

+0

工程偉大的thx! :D和我沒有混合:/並且不知道如何使用它... – 2012-02-23 08:28:52

+0

你不需要混合,但是如果你想製作需要看起來有點兒的東西,好一點 :) – 2012-02-23 09:26:18

相關問題