2

TextBlock 的样式(如下)对 DataTemplate 的 TextBlock 没有影响。如果我在样式和模板中都将 TextBlock 更改为 TextBox,则样式会按我的预期应用。为什么 TextBlock 会忽略样式?

谢谢你,

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:l="clr-namespace:SilverlightApplication1" mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontSize" Value="20" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="FontSize" Value="20" />
        </Style>
        <DataTemplate DataType="l:MyObject">
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </UserControl.Resources>

    <StackPanel>
        <ItemsControl>
            <ItemsControl.Items>
            <l:MyObject Name="Frank" />
            </ItemsControl.Items>
        </ItemsControl>
    </StackPanel>
</UserControl>
4

0 回答 0