3
嘿我試圖在WPF中設置樣式按鈕。我有一個基本樣式:WPF BasedOn造型
<Style x:Key="buttonStyle" TargetType="{x:Type ButtonBase}">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="ButtonBaseControlTemplate" TargetType="{x:Type ButtonBase}">
<Grid SnapsToDevicePixels="True">
<Border x:Name="Bd" Background="#9BC4E2" BorderBrush="Black"
BorderThickness="3,3,3,3" CornerRadius="7,7,7,7" Padding="5,5,5,5">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="Content"
ContentSource="Content"
RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
<-- Removed triggers here -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但我需要用這個切換按鈕也僅僅是用來改變背景器isChecked顏色。但我不能訪問邊界設置背景,當我嘗試這樣的:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource buttonStyle}">
</Style>
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource buttonStyle}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="White"/> <-- Need to specify target name of the border here somehow -->
</Trigger>
</Style.Triggers>
</Style>
有什麼建議嗎? TA
這很好,謝謝,我們有一個工作的解決方案! – 2011-03-11 16:24:51