【问题标题】:DataTemplate only specify binding not the typeDataTemplate 只指定绑定而不是类型
【发布时间】:2018-11-15 15:41:23
【问题描述】:

我有这段代码,其中有一个包装子类的列表。我想指定 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}"/>

【问题讨论】:

    标签: c# wpf mvvm data-binding


    【解决方案1】:

    我想我忘记了 ContentPresenter 是一个东西,但它最终让我得到了我正在寻找的东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-29
      • 2016-10-26
      • 2020-03-24
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多