我在app.xaml
中定义了这个<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="FontFamily" Value="Cailibri"></Setter>
</Style>
并在Window1.xaml
中定义<Style x:Key="BASE">
<Setter Property="Control.FontSize" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=MyFontSize}">
</Setter>
<Setter Property="Control.FontFamily" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=MyFontFamily}">
</Setter>
<Setter Property="Control.HorizontalAlignment" Value="Left">
</Setter>
</Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource BASE}">
</Style>
<Style TargetType="lc:LayoutItem" BasedOn="{StaticResource BASE}">
<Setter Property="LabelStyle">
<Setter.Value>
<Style TargetType="lc:LayoutItemLabel" BasedOn="{StaticResource BASE}">
</Style>
</Setter.Value>
</Setter>
</Style>
<lc:LayoutControl x:Name="HeadLayout" lc:LayoutControl.CustomizationLabel="test" ItemInsertionPointIndicatorStyle="{StaticResource myInsertionPointIndicator}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
AllowNewItemsDuringCustomization="False" AllowAvailableItemsDuringCustomization="True" Orientation="Horizontal">
<lc:LayoutGroup Orientation="Vertical" View="Group" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<lc:LayoutItem Label=" CDFEG " x:Name="StoreName" >
<TextBlock TextWrapping="Wrap" Text="ABCDEFG"/>
</lc:LayoutItem>
</lc:LayoutGroup>
</lc:LayoutControl>
当我更改fontsize或fontfamily属性时,它在app.xaml中未定义TextBlock时工作正常。我已经搜索了很长时间了,但对我来说还没有解决方案。 thx。
。任何建议都会有所帮助答案 0 :(得分:0)
使用DataTemplate解决了这个问题。
<Style TargetType="lc:LayoutItem" x:Key="myLayoutItemStyle" BasedOn="{StaticResource BASE}">
<Setter Property="LabelTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" >
<TextBlock.Style>
<Style BasedOn="{StaticResource BASE}">
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
在此处查看http://documentation.devexpress.com/#WPF/DevExpressXpfLayoutControlLayoutItem_LabelTemplatetopic。