[英]Custom xmlns namespaces not working
我正在嘗試按照這些說明將標簽內容分成單獨的文件。 這是我的文件結構
我正在嘗試將文件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#聊天,我留下以為這是不尋常的:
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.