Warm tip: This article is reproduced from stackoverflow.com, please click
c# namespaces uwp-xaml code-behind

uwp c# 2019: How to refer to RootGrid

发布于 2020-05-03 03:29:42

Sorry. I think I've found it.

I thought the suggestion reference to "RootGrid" was to a VS Named Space, like System.Windows.RootGrid I'm relatively sure they intended me to refer to a Grid in my XAML.

Realizing this probability was a "DUH" moment. So, just replacing RootGrid with my XAML name "GridBoard" will probably solve the issue. I haven't got the close of the Control to work yet, but he naming issue is at least being found.

To answer the question. Help, is a User control file in ScqWander Program. localUCHelp was the name used to create an instance on the Page.


Quick overview: How do I refer to RootGrid?

I get RootGrid "Does not exist in current context"

I am using VS 2019 and have a C# project, using XAML. I wrote a UserControl and am trying code a Button to Close the control (when clicked work from within the control). I got a suggestion which included the sample below. Google has turned up nothing. The code is within the namespace

public sealed partial class MainPage : Page  
void Page_Loaded(object sender, RoutedEventArgs e)
{
 ScqWander.Help localUCHelp = new ScqWander.Help();
 localUCHelp.HelpUserControlCloseEvent += new EventHandler(BtnPXClose);
 RootGrid.Chilren.Add(localUCHelp);
}

Questioner
ScCrow
Viewed
14
ScCrow 2020-02-14 10:15

I was simply thinking that "RootGrid" reference to which I could refer (as in Using System.Whateverxxxx) when I should have been referring to the Grid I defined in my XAML. I just did not recognize what was being said in the example.