如何在 Windows Phone 8.1 中获取页面的 x:Class 属性?

How to get x:Class property of Page in Windows Phone 8.1?

<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Loaded="Page_Loaded"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

我有一个应用程序。我想得到一个页面的 x:class 来区分页面。如何获得 App6.MainPage ?

我正在尝试这个 我有 ListControl 功能: 私有无效 ListControl() { 框架 currentFrame = null; 尝试 { 当前帧 = Window.Current.Content 作为帧;

        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(e.Message);
        }
        waitingControls.Add(currentFrame);
        int countChild = 1;

        while (waitingControls.Count > 0)
        {
            DependencyObject currentObject = waitingControls[0];
            waitingControls.RemoveAt(0);
            openedControls.Add(currentObject);

            countChild = VisualTreeHelper.GetChildrenCount(currentObject);
            for (int i = 0; i < countChild; i++)
                waitingControls.Add(VisualTreeHelper.GetChild(currentObject, i));
        }
    }

和 ClearListControl 函数

 private void ClearListControl()
    {
        openedControls.Clear();
        waitingControls.Clear();
    }

。最后,我得到了属性页:

private async void GetPropertiesPage()
    {
         ListControl();

         for (int i = 0; i < openedControls.Count; i++)
         {
             if (openedControls[i] is Page)
             {
                 string propertiesPage = "";
                 Page page = openedControls[i] as Page;

                 //if (page.Name.Equals(""))
                 //{


                     var temp = page.TransformToVisual(Window.Current.Content as Frame);
                     Point screenCoords = temp.TransformPoint(new Point(0, 0));

                     propertiesPage += ",X," + Math.Round(screenCoords.X, 0) + Environment.NewLine + ",Y," + Math.Round(screenCoords.Y, 0) + Environment.NewLine;
                     propertiesPage += ",Content," + page.Content + Environment.NewLine + ",Name," + page.Name + Environment.NewLine;
                     propertiesPage += ",AllowDrop," + page.AllowDrop.ToString() + Environment.NewLine;
                     StackPanel panel = (StackPanel)page.Content;

                     if (propertiesPage.Length > 0)
                     {
                         Task.Run(async () =>
                         {
                             SendData(propertiesPage);
                         }).Wait();
                     }

                     for (int j = 0; j < openedControls.Count; j++)
                     {
                         if (openedControls[j] is Grid)
                         {
                             Grid gr = (Grid)openedControls[j];
                             gr.Children.Remove(ca);
                             ca = new Canvas();
                             line = new Rectangle()
                             {
                                 StrokeThickness = 2,
                                 Stroke = new SolidColorBrush(Colors.Red),
                                 Height = page.ActualHeight,
                                 Width = page.ActualWidth,
                             };
                             page.UpdateLayout();
                             ca.Children.Add(line);
                             gr.Children.Add(ca);
                             Canvas.SetTop(line, screenCoords.Y - 25);
                             Canvas.SetLeft(line, screenCoords.X);
                             await Task.Delay(2000);
                             gr.Children.Remove(ca);
                             break;

                         }
                     }

                 //}
             }
         }

         ClearListControl();
    }

请帮助我。感谢您的帮助!

你有两个选择。您可以检查类型或类型名称。

使用 is 运算符检查类型可能更好,因为您将在编译时检查它是否为有效类型:

if (page is App6.MainPage)
{
  ...
}

如果由于某种原因这不起作用,您可以改用类型名称:

if (page.GetType().FullName == "App6.MainPage")
{
  ...
}