To have a CustomPage instead of default Page for base of all pages in the application.
guess_me_if_u_can
126
Reputation points
Instead of having the base Page for all the xaml page files, I need to have my CustomPage.xaml. I have created a CustomPage and had it as a base of my SettingsPage.xaml. It compiles successfully but throws a warning. Please check the code follows,
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace CustomPageTest
{
public partial class CustomPage : Page
{
public CustomPage()
{
this.InitializeComponent();
this.Loaded += CustomPage_Loaded;
}
private void CustomPage_Loaded(object sender, RoutedEventArgs e)
{
if (MyTextBlock != null)
{
}
}
}
}
<Page
x:Class="CustomPageTest.CustomPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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>
<Frame x:Name="Frame" />
<TextBlock x:Name="MyTextBlock" Text="Hello" />
</Grid>
</Page>
namespace CustomPageTest
{
public sealed partial class SettingsPage : CustomPage
{
public SettingsPage()
{
this.InitializeComponent();
}
}
}
<local:CustomPage
x:Class="CustomPageTest.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CustomPageTest"
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>
</local:CustomPage>
In the CustomPage_Loaded event, the MyTextBox property is null.
Please check the warning thrown