我有一个简单的窗口,带有一些按钮,并在上面显示内容。现在,根据我可以导航到的页面数量(PageViewModels.Count),我想要设置按钮样式:
<DockPanel Background="White">
<Border DockPanel.Dock="Bottom">
<ItemsControl ItemsSource="{Binding PageViewModels}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding PageViewModels.Count}" Margin="0,19"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="NavigationButton"
Content="{Binding Name}"
Command="{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CommandParameter="{Binding }"
/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding PageViewModels.Count}" Value="2">
<Setter Property="Style" TargetName="NavigationButton" Value="{StaticResource RoundCornerButtonPinkFilledSmall}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PageViewModels.Count}" Value="{StaticResource GridColumnsBig}">
<Setter Property="Style" TargetName="NavigationButton" Value="{StaticResource RoundCornerButtonPinkFilledBig}"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
<ContentControl Content="{Binding CurrentPageViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
</DockPanel>
上面的代码正确设置了UniformGrid
列的数量,但是style属性根本没有设置(如果我将Style="{StaticResource RoundCornerButtonPinkFilledBig}"
放在button标记中,那么它就起作用了,所以样式似乎是好)。我尝试从StaticResource或只是数字中输入值。
我在这里做什么错了?