I'm trying to get an XAML element with its own name from another C# class, but it's returning always null, why?
Here's the target XAML with its C# class:
XAML:
<Page
x:Class="myApp.SubSpace.SomePage"
IsTabStop="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:myApp.SubSpace"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="target">
</Grid>
</Page>
C#:
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace myApp.SubSpace
{
public sealed partial class SomePage : Page
{
public SomePage()
{
InitializeComponent();
}
}
}
And here's the code it's giving me a null result:
using myApp.SubSpace;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace myApp.Core
{
public class Main
{
private Grid target;
public Main() {
FrameworkElement page = new SomePage();
this.target = (Grid)page.FindName("target");
}
}
}
The code is very simplified, but the very important things are there. After calling a new Main
object, its target
field is null. What's wrong?
Thanks in advance!