【问题标题】:Tabcontrol with different pages (included in xaml or extern page) as tabcontent具有不同页面(包含在 xaml 或外部页面中)作为 tabcontent 的 Tabcontrol
【发布时间】:2016-07-13 05:49:13
【问题描述】:

您好,感谢您的阅读和帮助:-)

下面是我的代码和语句。

我有我的MainWindow.xaml,其中我有我的CheckBoxTabControl

<CheckBox Grid.Column="8" Grid.Row="2" Name="checkBoxCommon" HorizontalAlignment="Right" VerticalAlignment="Center" IsChecked="{Binding IsCheckedCommon}"/>

    <Grid Grid.Column="0" Grid.ColumnSpan="10" Grid.Row="4">
    <TabControl ItemsSource="{Binding Path=DpConfigCol>
    <TabControl.ItemTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding Path=DpConfigName}>
                <ContentControl.Resources>
                    <DataTemplate DataType="types:ConfigCommon">
                    </DataTemplate>
                    <DataTemplate DataType="types:ConfigAdress">
                    </DataTemplate>
                </ContentControl.Resources>
            </ContentControl>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <ContentControl>
                <ContentControl.Resources>
                    <DataTemplate DataType="types:ConfigCommon">
                        <TextBlock Text="hallo" Width="150"/>
                    </DataTemplate>
                    <DataTemplate DataType="types:ConfigAdress">
                    </DataTemplate>
                </ContentControl.Resources>
            </ContentControl>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

如果我勾选我的复选框,它将向我的ObservableCollection() 添加一个新模型。

private bool _isCheckedCommon;
public bool IsCheckedCommon
{
    get { return _isCheckedCommon; }
    set
    {
        _isCheckedCommon = value;

        if (_isCheckedCommon == true)
        {
            DpConfigCol.Add(new ConfigCommon("Common"));
        }
        else
        {
            foreach (object item in DpConfigCol)
            {
                if (item.GetType().ToString()==typeof(ConfigCommon).FullName.ToString())
                {
                    DpConfigCol.Remove(item);
                    break;
                }
            }
        }
        return;
    }
}

我使用这个名为DpConfigCol 的集合绑定到我的tabcontrol

现在我的问题是:

如何使属性(来自我的模型:ConfigCommon)在我的tabcontrol.ContentTemplate 中可见?如果有不止一个复选框包含更多模型? 有没有办法在 Tabcontrol.contentTemplate 中为多个模型实现多个模板?

【问题讨论】:

    标签: c# wpf xaml mvvm tabcontrol


    【解决方案1】:

    TLDR; (只读标题)

    我还必须开发一个曾经使用过标签的应用。您可以在标签中使用&lt;Frame&gt;,并将其Content 设置为您想要的任何XAML page

    【讨论】:

    • 但是如果我有两个带有两个不同框架的复选框,我该如何在我的 .xaml 中实现呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 2016-10-13
    相关资源
    最近更新 更多