我有这段代码,其中有一个包装好的子类列表。我想指定ContentTemplate直接绑定到子类,而不是包装类。我的问题是如何在不指定类型的情况下指定绑定(因为这由我的app.xaml中的数据模板解析)。
代码:
<TabControl Name="tc_TabItems"
Grid.Column="2"
Grid.ColumnSpan="3"
ItemsSource="{Binding Value.CheckedItems}"
SelectedItem="{Binding SelectedItem}">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type vms:CommandsViewModel}">
<TextBlock Text="{Binding Value.Name}"/>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
App.xaml:
<DataTemplate DataType="{x:Type commandBaseModels:MotionCommandViewModel}">
<commandBase:MotionCommandView/>
</DataTemplate>
<DataTemplate DataType="{x:Type commandBaseModels:NonMotionCommandViewModel}">
<commandBase:NonMotionCommandView/>
</DataTemplate>
对于选项卡的标题,您可以看到我将文本绑定到子类,但是我手动设置了一个文本块,我基本上是想做同样的事情,但没有指定要放在那里的控件。像这样
<TabControl.ContentTemplate Binding="{Value}"/>
答案 0 :(得分:0)
我想我忘记了ContentPresenter
是一回事,但最终让我得到了想要的东西