【发布时间】:2016-01-31 04:24:32
【问题描述】:
我是 Windows 10 应用开发的新手。我正在尝试将我的自定义 UserControl 嵌入到我的应用程序的页面中。出于某种原因,内容完全被我在 XAML 页面中放入的任何内容所取代。为了给出更好的解释,下面是代码:
AppView.xaml(控件)
<UserControl
x:Class="Sirloin.AppView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Sirloin"
xmlns:h="using:Sirloin.Helpers">
<SplitView x:Name="splitView" DisplayMode="CompactOverlay">
<SplitView.Pane>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--The hamburger-->
<Button Click="OnHamburgerClicked" Grid.Row="0" Style="{StaticResource MenuButtonStyle}">
<Button.DataContext>
<local:MenuItem Symbol=""/>
</Button.DataContext>
</Button>
<!--Buttons just below the hamburger-->
<ListView x:Name="topView"
Grid.Row="1"
ItemTemplate="{StaticResource ListViewItemTemplate}"/>
<!--Buttons toward the bottom of the menu-->
<ListView x:Name="bottomView"
Grid.Row="3"
ItemTemplate="{StaticResource ListViewItemTemplate}"/>
</Grid>
</SplitView.Pane>
<SplitView.Content>
<!--Where I'd like the content specified in MainPage to appear-->
<Frame x:Name="frame" Background="White"/>
</SplitView.Content>
</SplitView>
</UserControl>
MainPage.xaml
<Page
x:Class="Sirloin.Example.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="using:Sirloin"
xmlns:local="using:Sirloin.Example">
<s:AppView>
<Grid Background="White">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Hello, world!"/>
</Grid>
</s:AppView>
</Page>
当MainPage 在 VS 设计器中呈现时,就好像我的用户控件的内容已被完全删除并替换为主页中指定的任何内容。为了给你一个想法,这里是设计师的截图:
如您所见,没有菜单或SplitView 或我在自定义控件中添加的任何内容;唯一存在的是我在 XAML 中为 MainPage 指定的 TextBlock。
无论如何,为什么会发生这种情况,我可以做些什么来解决它?
编辑:找到了我一直在寻找的解决方案 here,但 Peter Duniho 的回答已被接受,因为它更好地解释了正在发生的事情。
【问题讨论】:
标签: c# xaml windows-10 win-universal-app uwp