在下面的xaml中,我在MainWindow xaml中创建了一个错误(' 14'不适用于属性' Style')的值。我仍然可以运行应用程序,奇怪的是,样式在运行时可以正确显示。
<UserControl x:Class="PerfectCode.TVShowManager.UserInterface.Views.TVShowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControls="clr-namespace:PerfectCode.TVShowManager.UserInterface.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<GroupBox>
<GroupBox.Header>
HERE I AM NOT ALLOWED TO SET THE STYLE ON MY TEXTBLOCK
<TextBlock Style="{StaticResource LargeText}" Text="{Binding Name}"/>
</GroupBox.Header>
<TabControl ItemsSource="{Binding Seasons}" SelectedItem="{Binding SelectedSeason}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Name}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<userControls:SeasonControl/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</GroupBox>
</UserControl>
无论如何,当我这样做时,我的MainViewWindow.xaml
会出错<Window x:Class="PerfectCode.TVShowManager.UserInterface.MainWindow"
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:views="clr-namespace:PerfectCode.TVShowManager.UserInterface.Views"
mc:Ignorable="d"
Title="Manage your TV Shows"
Width="1500" Height="900">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<views:ActionBar Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"/>
<views:TVShowListControl Grid.Row="1" Grid.Column="0"/>
<GridSplitter Grid.Row="1" Grid.Column="1" Width="5" HorizontalAlignment="Stretch"/>
THE NEXT LINE HAS THE ERROR
<views:TVShowControl Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" DataContext="{Binding SelectedTVShow}"/>
</Grid> </Window>
评论中要求的样式:
<Style x:Key="SmallText" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="18"/>
</Style>
<Style x:Key="LargeText" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="26"/>
</Style>
正如我之前所说,一切都运作得很好。该应用程序可视化正确。 groupbox的标题包含&#34; LargeText&#34;的所有属性。并呈现前景色白色。
当我从文本块中删除样式时,然后只有错误消失(重建后)。
我正在使用VS2015和.NET4.6(以及R#9.2,如果它与它有任何关系)。
我在XAML中做错了什么吗?