簡體   English   中英

自定義xmlns命名空間不起作用

[英]Custom xmlns namespaces not working

我正在嘗試按照這些說明將標簽內容分成單獨的文件。 這是我的文件結構
具有MainWindow.xaml的TabContext文件夾中的TabAttributesContext.xaml

我正在嘗試將文件2的內容與文件1加載在一起,以便它們一起工作。 這是文件2:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl x:Key="Tab1Control">
        <DataTemplate DataType="TabItem">
            <TextBlock Text="Test text"></TextBlock>
        </DataTemplate>
    </UserControl>
</ResourceDictionary>

和文件1的相關部分:

<Window x:Class="MnMCharacterCreator.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tabs="TabContent/TabAttributesContent">
        ...
    <!--Creates a tabbing system, with a grid defined by each ItemsControl-->
    <TabControl Name="WindowTabs">
        <TabItem Name="WindowTab1" Header="Attributes">
            <!--This is where the UserControl from file 2 should be loaded-->

參觀完 2個相關問題(有幾十人),並要求對C#聊天,我留下以為這是不尋常的:

WPF項目錯誤消息中不支持使用選項卡

Intellisense對於<tabs:不會顯示任何內容<tabs:即使我手動鍵入現有名稱或其他名稱,也會給出錯誤消息,這意味着這不是設計者的問題。 是VS2012中的完整解決方案。

具體來說,我要問的問題是如何使用另一個xaml文件中的內容? 如果無法使用xmlns ,那是什么?

您可能想為標簽項創建用戶控件,如

<UserControl x:Class="WPFSample.TabItem1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
<Grid>
    <TextBlock Height="100" Width="100" Text="Hi from tab item 1"/>
</Grid>

然后使用此方法在MainWindow中添加名稱空間:

<Window x:Class="WPFSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    xmlns:local="clr-namespace:WPFSample">
<Grid>
    <TabControl>
        <TabItem Header="XYZ">
            <local:TabItem1/>
        </TabItem>
    </TabControl>
</Grid>

准備使用。

希望您已將用戶控件xaml.cs從XYZ:Window更改為XYZ:UserControl並構建了一次解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM