<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 功能: private void ListControl() { Frame currentFrame = null; 尝试 { currentFrame = Window.Current.Content as Frame;
}
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();
}
请帮我。感谢您的帮助!