【发布时间】:2015-09-14 06:12:45
【问题描述】:
我有 ComboBox 的样式。并为其设置 Font-family。
为项目设置字体,但不为选定项目设置。
<DataTemplate x:Key="SelectionBoxTextTemplate">
<TextBlock FontFamily="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}, Path=FontFamily}" Text="{Binding}"/>
</DataTemplate>
<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="MinWidth" Value="120"/>
<Setter Property="FontFamily" Value="{StaticResource IranSansFontFamily}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>
<ToggleButton
Name="ToggleButton"
Grid.Column="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ComboBoxToggleButton}">
</ToggleButton>
<ContentPresenter
Name="ContentSite"
HorizontalAlignment="Left"
Margin="3,3,23,3"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{StaticResource SelectionBoxTextTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False"/>
【问题讨论】: