2010-07-29 65 views
1

我已經創建了基於icrosoft_Windows_Themes2:ButtonChrome的自己的按鈕。我想擺脫默認邊框,我試圖將其設置爲空或透明,但我仍然得到一個白色的邊框。Windows主題ButtonChrome邊框

這裏是我的標記:

<Microsoft_Windows_Themes2:ButtonChrome x:Name="ibAero" Visibility="Collapsed" SnapsToDevicePixels="true" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" RoundCorners="True" Background="{TemplateBinding Background}" BorderBrush="Transparent" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" OverridesDefaultStyle="True"> 
    <Border x:Name="bd" CornerRadius="10" BorderThickness="1" BorderBrush="{Binding ElementName=IB, Path=BorderBrush}"> 
     <StackPanel Orientation="Horizontal" Margin="8,1,5,1"> 
      <TextBlock Text="{Binding ElementName=IB, Path=Text}" Foreground="{Binding ElementName=IB, Path=TextForeground}" Margin="{Binding ElementName=IB, Path=TextMargin}" VerticalAlignment="Center"/> 
     </StackPanel> 
    </Border> 
</Microsoft_Windows_Themes2:ButtonChrome> 

編輯:

確定。我改變了這樣的標記:

<Border x:Name="ibAero" Visibility="Collapsed" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" CornerRadius="3" BorderThickness="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"> 
    <StackPanel x:Name="ibAeroPanel" Orientation="Horizontal" Margin="8,1,5,1"> 
     <Image Source="{Binding ElementName=IB, Path=Image}" Width="{Binding ElementName=IB, Path=ImageWidth}" Height="{Binding ElementName=IB, Path=ImageHeight}"/> 
     <TextBlock Text="{Binding ElementName=IB, Path=Text}" Foreground="{Binding ElementName=IB, Path=TextForeground}" Margin="{Binding ElementName=IB, Path=TextMargin}" VerticalAlignment="Center"/> 
    </StackPanel> 
</Border> 

如何在我的usercontrol中設置默認樣式?

回答

0

我建議不要在您的模板中包含Button Chrome。如果你想重新創建它在鼠標懸停和按下時提供的一些很好的效果,它將需要額外的工作,但它會擺脫邊界。

+0

如何在我的用戶控件中設置默認樣式? – Sys 2010-08-02 07:28:51

1

回答這個問題是由Meleak張貼此鏈接:How to remove ButtonChrome border (when defining the template of a border)?

的原因,你得到那個白色邊框是因爲它在ButtonChrome控制在代碼中添加。沒有辦法通過模板實現解決方案。刪除邊框的唯一方法是編寫您自己的控件版本。

我google了這個問題,並找到許多人提供模板「解決方案」的答案。他們中的任何一個都不可能按照建議工作。

將Meleak的修改過的ButtonChrome.cs控件添加到您的自定義WPF控件庫(組合框的禁用F4鍵是我個人庫存中的另一個),並且您可以輕鬆前往。