0

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;
    }
vladc77
  • 1,064
  • 3
  • 22
  • 47

2 Answers2

1

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.

danbord
  • 3,605
  • 3
  • 33
  • 49
  • Thank you for the interesting info. I'd like to find out what will be the syntax to access the methods I have in Content.xaml from MainPage.xaml with rootvisual? Thank you! – vladc77 Mar 26 '11 at 16:15
  • Is it possible to use here something similar to RountedCommands that are available only in WPF? Perphaps, it might be wrong direction. I am trying to understand if it will make sence. Thank you! – vladc77 Mar 26 '11 at 16:15
  • Add the XAML for your MainPage.xaml because its not clear how your content.xaml is loaded in your MainPage. – danbord Mar 26 '11 at 17:21
  • I decided to upload testing solutuon. you can get it from here: http://cid-0c29483cf3a6a14d.office.live.com/self.aspx/WPF%5E_Tests/ViewModelDeleteObjectDataGrid5.zip – vladc77 Mar 26 '11 at 18:40
  • I have a storyboard there which should be ran if the value 'currentItem.Status != "not published"'. That animation will introduce container with a button. Clicking that button should run 'Unpuslish_Status' method in the Page1.xaml. – vladc77 Mar 26 '11 at 18:43
0

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.)

danbord
  • 3,605
  • 3
  • 33
  • 49
  • Thank you! It is great. This worked for me to be able to access the method in the Page1. I am wondering about how to correctly apply 'Application.Current.RootVisual'. I put it in constructor. I tried it but it does not allow to access the object. I want to make 'grdMainPage_SystemMessages_Blue' object available. Please let me know how correctly use RootVisual. Thank you again. – vladc77 Mar 28 '11 at 19:04