好的。我在WPF中製作自定義控件是全新的,所以我需要很多指導。我想製作一個麪包屑按鈕,如this article,但這次是在WPF中。
我想我可以弄清楚自己如何畫出形狀......經過艱苦的工作,但現在我又有了一個擔憂。
我真的需要在繪製我的背景時獲取並使用標準的背景畫筆,不會改變System.Windows.Controls.Button
!在我的自定義控件中從`System.Windows.Controls.Button`複製樣式?
編輯:
請幫我...
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF_Bread_Crumb_Button"
xmlns:my="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<Style TargetType="{x:Type local:Crumb}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Crumb}">
<my:ButtonChrome Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" Name="Chrome" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" SnapsToDevicePixels="True">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" Margin="{TemplateBinding Control.Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" />
</my:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsKeyboardFocused" Value="True">
<Setter Property="my:ButtonChrome.RenderDefaulted" TargetName="Chrome" Value="True" />
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter Property="my:ButtonChrome.RenderPressed" TargetName="Chrome" Value="True" />
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="Control.Foreground" Value="#FFADADAD" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
這隻會導致我的Visual Studio崩潰...... :( – Vercas 2011-05-03 17:13:29
您需要獲取所有資源漸變引用以及-_- – 2011-05-03 17:41:15
@Vercas:我有一個有點誤導性的鏈接,因爲在其父網站上找到默認樣式,請檢查答案中的更新鏈接。 – 2011-05-03 17:57:25