1

我在我的 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 时,它可以正常工作。我已经搜索了很长时间,但对我来说还没有一个解决方案。任何建议都会有所帮助,谢谢。

4

1 回答 1

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

于 2012-09-04T02:14:36.470 回答