第一种样式的 xaml 可以按我的意愿工作,使用 setter 生成一个带有 Wingding 字形的按钮来布置内容及其属性。这种风格的第二个版本尝试做同样的事情,但使用 DataTemplate 作为 Content,但它只显示 DataTemplate 的类型(即 System.Windows.DataTemplate)。
- 为什么第 2 版显示的内容与第 1 版不同?
- 假设修复是微不足道的,出于个人喜好之外的任何原因,一种风格的版本是否会比另一种更可取?
注意:我正在显示绑定和触发器,以防其中有影响内容的东西,但这只是样式的第一部分有所不同
干杯,
贝里尔
样式 1
显示:
<Style x:Key="EditCommandButtonStyle" TargetType="{x:Type Button}" >
<Setter Property="Content" Value="a" />
<Setter Property="Foreground" Value="Navy" />
<Setter Property="FontFamily" Value="Wingdings 3" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Width" Value="30" />
<Setter Property="Height" Value="Auto" />
<!--What makes it an Edit button-->
<Setter Property="Command" Value="{Binding ActivateThisSatelliteVmCommand}"/>
<Setter Property="ToolTip">
<Setter.Value>
<TextBlock>
<TextBlock.Text>
<Binding Path="HeaderLabel" StringFormat="{resx:Resx ResxName=Smack.Core.Presentation.Resources.MasterDetail, Key=Item_Edit_Label}"/>
</TextBlock.Text>
</TextBlock>
</Setter.Value>
</Setter>
<!-- WHen its available -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="theBorder" CornerRadius="4">
<ContentPresenter x:Name="theContent" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter TargetName="theContent" Property="Visibility" Value="Hidden"/>
<Setter TargetName="theBorder" Property="Background" Value="Transparent"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="theContent" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="theContent" Property="Visibility" Value="Visible"/>
<Setter TargetName="theBorder" Property="Background" Value="Orange"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
风格 2
显示“System.Windows.DataTemplate”
<Style x:Key="EditCommandButtonStyle" TargetType="{x:Type Button}" >
<Setter Property="Content">
<Setter.Value>
<DataTemplate>
<TextBlock Text="a" FontFamily="Wingdings 3" FontWeight="Bold" FontSize="18" Foreground="Navy" />
</DataTemplate>
</Setter.Value>
</Setter>
<!--What makes it an Edit button-->
<Setter Property="Command" Value="{Binding ActivateThisSatelliteVmCommand}"/>
<Setter Property="ToolTip">
<Setter.Value>
<TextBlock>
<TextBlock.Text>
<Binding Path="HeaderLabel" StringFormat="{resx:Resx ResxName=Core.Presentation.Resources.MasterDetail, Key=Item_Edit_Label}"/>
</TextBlock.Text>
</TextBlock>
</Setter.Value>
</Setter>
<!-- When its available -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="theBorder" CornerRadius="4">
<ContentPresenter x:Name="theContent" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter TargetName="theContent" Property="Visibility" Value="Hidden"/>
<Setter TargetName="theBorder" Property="Background" Value="Transparent"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="theContent" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="theContent" Property="Visibility" Value="Visible"/>
<Setter TargetName="theBorder" Property="Background" Value="Orange"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>