FontSize Style Ignored by TextBlock in DataTemplate

不羁岁月 提交于 2020-01-05 02:51:05

问题


The style for TextBlock (below) has no effect on the DataTemplate's TextBlock. If I change TextBlock to TextBox in both the style and template, the style applies as I would expect. Why does TextBlock ignore the style?

Thank you,
Ben

<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>

来源:https://stackoverflow.com/questions/13293627/fontsize-style-ignored-by-textblock-in-datatemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!