【问题标题】:Showing Header of Tab using Prism使用 Prism 显示选项卡的标题
【发布时间】:2009-04-07 15:41:26
【问题描述】:

我正在使用 Prism 并且有一个区域是 TabControl。我将 TabControl.ItemTemplate 上的 DataTemplate 设置为 IView 类型的接口。 IView 有一个 Title 和 Description 字符串。当我使用 IView 调用 RegisterViewWithRegion 时,会添加选项卡,但标题上不显示任何描述。我可以不绑定到接口上的属性还是缺少其他东西?

manager.AddToRegion("ContentZone", new PrimaryView()); //实现IView

<TabControl x:Name="ContentZone" cal:RegionManager.RegionName="ContentZone" Grid.Row="1" umn="0">
<TabControl.ItemTemplate>
    <DataTemplate DataType="{x:Type oasis:IView}">
        <DockPanel ToolTip="{Binding Path=Description}">
            <Label Padding="0"
                   Content="{Binding Path=Title}"
                   VerticalAlignment="Center" />

编辑:我找到了一个解决方案,虽然我觉得它不是很好。出于某种原因,无论我做什么,DataTemplate 的 DataContext 总是返回为空,我尝试了 DataTempalteSelector,但该项目本身也是空的。我尝试改为改为基本抽象类,但也没有用。所以这就是我对绑定本身的最终结果:

{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}, Path=DataContext.Title}

【问题讨论】:

  • 你不是在使用 TabItem.HeaderTemplate 吗?
  • 哇,不知道,已经很久很久从 Prism 搬走了,现在还维护吗?

标签: c# wpf


【解决方案1】:

您不能将DataTemplate 与接口相关联。它必须与类型直接关联。如果你想通过一个接口进行关联,你可以考虑实现一个DataTemplateSelector,它检查项目是否实现了IView,并相应地返回一个DataTemplate

【讨论】:

  • 所以我试了一下,但 SelectTemplate 方法中返回的项目始终为空。我像下面这样注册它。断点命中,但项目为空。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多