开发者

How to run methods across pages in Silverlight?

开发者 https://www.devze.com 2023-02-19 15:54 出处:网络
I need to be able to set the visibility of the Border to be visible for 10 seconds. The border resides in MainPage.xaml which is parent to Content.xaml. The trick is that I need to change the visibili

I need to be able to set the visibility of the Border to be visible for 10 seconds. The border resides in MainPage.xaml which is parent to Content.xaml. The trick is that I need to change the visibility of the border by clicking ContextMenu item that is accessible from Content.xaml which is loaded as a UserControl into MainPage.xaml. It is also should be conditional bases on the cell value in the datagrid. I established a method in Content.xaml which should conditionally change visibility of the border in MainPage.xaml. Since the border is out of the scope, I need to find a way to be able wire to it.

Code to set the visibility based on the content in cell value in datagrid:

private void Delete(object sender, RoutedEventArgs e)
    {
        Packages_DataViewModel currentItem = MasterTile.SelectedItem as Packages_DataViewModel;
        if (currentItem.Status != "has content")
        {
            this.MainPageBorder.Visibility = Visibility.Visible;
        }
        else
        {
            mv.DeletePackagesItem((Packages_DataViewModel)(MasterTile.SelectedItem));
        }
    }

I also need to run a method which I use in Content.xaml to modify data grid content from a button in MainPage.xaml.开发者_开发问答 Any ideas are highly appreciated!

Code to update the cell value:

private void Status(object sender, RoutedEventArgs e)
    {
        Packages_DataViewModel currentItem = MasterTile.SelectedItem as Packages_DataViewModel;
        currentItem.Status = "has content";
        this.MainPageBorder.Visibility = Visibility.Collapsed;
    }


The MainPage.xaml should always be your rootvisual. You can easily access the object via the

following code :

Application.Current.RootVisual

and this is accesible from everywhere in your silverlight application.


To answer your comment, the RootVisual IS your MainPage.xaml.

To access Methods in your Content.xaml, you need to set those methods to public. Then from the MainPage.xaml you can call it this way (by casting the content of the ucMainPage_MainContent to Page1 type).

((Page1)this.ucMainPage_MainContent.Content).TestMethod1();

(TestMethod1 is a new public method I added to Page1.xaml.)

0

精彩评论

暂无评论...
验证码 换一张
取 消