我正在尝试为我的 WP 应用程序创建一个自定义基页。我通过创建一个cs
继承自这样的新类文件来做到PhoneApplicationPage
这一点:
public class BasePage: PhoneApplicationPage
{
//handle common non-visual stuff here
}
问题是我想在每个使用的页面上添加一个控件,BasePage
但 BasePage 没有LayoutRoot
或任何我可以将控件附加到的可视元素。有没有办法可以将相同的控件添加到所有使用 BasePage 的页面,这样我就不必每次都复制/粘贴它?
编辑:根据 TriggerPin 的回答添加 XAML。我为我创建了一个新的 XAML 文件,BasePage.cs
但这会引发错误BasePage.g.cs
:“MyApp.MainPage 已经包含 '_contentLoaded' 的定义”(以及 'LayoutRoot' 和 'InitializeComponent' 的类似消息)
<local:BasePage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyApp.Template"
x:Class="MyApp.MainPage"
mc:Ignorable="d">