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>