WPF 导航页面面包屑
我找到了使用面包屑而不是页面导航按钮的代码。这段代码非常适合将页面设置为启动。我的问题是我需要一个带有框架控件的窗口作为启动,这导致面包屑根本不显示。我的造型似乎缺少一些东西。类型曾经是 NavigationWindow 但我将它们更改为 Frame 以尝试获得可行的解决方案。
<Style TargetType="Frame" x:Key="{x:Type Frame}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Frame">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding
RelativeSource={RelativeSource AncestorType={x:Type Frame}},
Path=BackStack}">
<!--Force the ItemsContol to use a wrap panel as Items host-->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:InverseWrapPanel KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.DirectionalNavigation="Cycle"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="NavigationCommands.NavigateJournal"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
Content="{Binding Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<WrapPanel>
<TextBlock Name="text1" FontWeight="Bold" Text="{TemplateBinding Content}"/>
<TextBlock Name="text2" FontWeight="Bold" Text=">>" Margin="2,0,0,0"/>
</WrapPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="text1" Property="Foreground" Value="Blue"/>
<Setter TargetName="text2" Property="Foreground" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<AdornerDecorator Grid.Row="2">
<ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>
</AdornerDecorator>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I found code to use a breadcrumb instead of the navigation buttons for my pages. This code works perfect with setting a page as the startup. My problem is that I need to have a window with a frame control as the startup and this is causing the breadcrumb to not show at all. I seem to be missing something with my styling. The types used to be NavigationWindow but I changed them to Frame to try and get a working solution.
<Style TargetType="Frame" x:Key="{x:Type Frame}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Frame">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding
RelativeSource={RelativeSource AncestorType={x:Type Frame}},
Path=BackStack}">
<!--Force the ItemsContol to use a wrap panel as Items host-->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:InverseWrapPanel KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.DirectionalNavigation="Cycle"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="NavigationCommands.NavigateJournal"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
Content="{Binding Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<WrapPanel>
<TextBlock Name="text1" FontWeight="Bold" Text="{TemplateBinding Content}"/>
<TextBlock Name="text2" FontWeight="Bold" Text=">>" Margin="2,0,0,0"/>
</WrapPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="text1" Property="Foreground" Value="Blue"/>
<Setter TargetName="text2" Property="Foreground" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<AdornerDecorator Grid.Row="2">
<ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>
</AdornerDecorator>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将:更改
为:
并且它应该有效。
Change:
to:
and its should work.