简体   繁体   中英

How to get Grid by name in a non-ui thread - Windows Phone

In my wp app, I am using silverlight 8.1 and

I have this grid in my MainPage.xaml

<Grid x:Name="LayoutRoot" Background="Transparent" HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
        ... 

I need to get it from another file and from another thread using this

Deployment.Current.Dispatcher.BeginInvoke(() => {
... do some work on UI here 
}

how can I get it programmatically?

I tried with MainPage.LayourRoot but it does not find LayoutRoot.

Ok, got the point. There is a way which tells what page the user is currently on:

var currentPage = ((App)Application.Current).RootFrame.Content as PhoneApplicationPage;

You simply get it and cast to a specific page type such as MainPage and then you are able to get reference to all visual elements with x:Name property.

Please tell me whether this code worked. I can't debug it since I'm no loger use SDK 8 and I'm sure this is not working on WinRT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM