【问题标题】:Need help to understand how to connect two xaml files需要帮助以了解如何连接两个 xaml 文件
【发布时间】:2019-09-09 21:55:17
【问题描述】:

我需要在不同的 xaml 文件中使用 tabItem,但我不知道该怎么做。

我访问过 Tonny Bores 在这里回答:TabItem in a separate XAML

但是我不明白 tabData 是从哪里来的。

<TabItem x:Class="Hysolate.DisplayTab"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="450" d:DesignWidth="800">
    <TabItem.Resources>
        <Style x:Key="TStyle"
               TargetType="TextBlock">
            <Setter Property="FontSize" Value="20" />
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
    </TabItem.Resources>
    <TabItem.Header>
        <TextBlock Style="{StaticResource TStyle}"  Text="Tab No. 2"></TextBlock>
    </TabItem.Header>
    <Grid>
        <TextBlock Text="Tab Data" />
    </Grid>
</TabItem>

<!-- And I want to use it here (different xaml file):

    <TabControl>
        <tabdata:DisplayTab></tabdata:DisplayTab>
    </TabControl>

-->

【问题讨论】:

    标签: c# .net wpf tabs


    【解决方案1】:

    tabdata 是您的 UserControl(xaml 文件 A),您需要在 xml 文件(xaml 文件 B) 标头中指定它,如下所示:

    <Window ... 
        xmlns:tabdata="clr-namespace:AssemblyName"//replace AssemblyName to your user control name
        ...
    />
    

    然后你就可以像你做的那样在 xaml 代码中使用它

        <tabdata:YourUserControl></tabdata:YouUserControl>
    

    【讨论】:

    • 您好,感谢您的回复。我如何实际使用标签数据?添加你写的那行之后,如何让xaml文件使用它?
    • 我在答案中修改了
    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 2017-06-19
    • 2016-05-03
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多