关于合并两个XAML文件的信息有些混乱,能否有人指点我正确的方向?(W10,VS2017,UAP,Midi)
我有 app.xaml
、MainPage.xaml
和 A.xaml
。我还有一个XAML资源字典。我想将 A.xaml
插入到 MainPage.xaml
中。
(实际上A被称为 MidiWrapper.xaml
)
app.xaml
<Application
x:Class="Kawai_ES110_Midi.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>
在遵循如何在WPF中使用C#组合多个XAML文件的方法后,当我将第一个解决方案放入app.xaml时,出现了访问冲突问题。
MainPage.xaml
<Page
x:Class="Kawai_ES110_Midi.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Kawai_ES110_Midi"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="XAMLWrapper.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
</Grid>
</Page>
A.xaml(又称MidiWrapper.xaml
)
<ResourceDictionary
x:Class="Kawai_ES110_Midi.MidiWrapper"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Kawai_ES110_Midi"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListBox x:Name="midiInPortListBox"/>
<ListBox x:Name="midiOutPortListBox"/>
</ResourceDictionary>
资源字典XAML,又称(XAMLWrapper.xaml
)
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>
非常感谢您的帮助。也许app.xaml需要引用资源字典和/或将“merged”标记放入MainPage和A中。或者MainPage和A也必须像字典一样工作。
我已经更新了我的代码,但仍然看不到列表框。