【发布时间】:2019-06-21 00:42:20
【问题描述】:
关于合并两个 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>
在How can i combine multiple XAML files using C# in WPF? 之后,当我将第一个解决方案放入 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 aka (XAMLWrapper.xaml)
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>
提前感谢您的帮助。也许 app.xaml 需要引用资源字典和/或将“合并”标签放入 MainPage 和 A。或者 MainPage 和 A 也必须像字典一样/行为? 我已经更新了我的代码,但我没有看到列表框仍然出现
【问题讨论】:
标签: c# xaml dictionary resources