Reputation: 876
I am currently working with windows phone 8.1 [RT] application , In my application I have hide Grid Visibility from class. For that I have create one public method on cs page
public void HideCancelButton()
{
grdCancle.Visibility = Visibility.Collapsed;
bdrCancel.Visibility = Visibility.Collapsed;
Debug.WriteLine("hide button");
//UpdateLayout();
}
and calld that method in following manner in helperClass.cs
MainPage mypage = new MainPage();
mypage.HideCancelButton();
it will debug "hide button" but doesn't hide grid
I have also use
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>{});
Upvotes: 0
Views: 100
Reputation: 2616
It won't hide the grid because you are not referencing the MainPage that is currently showing.
You should get the reference to the main page wherever you are calling the HideCancelButton method.
In your case the easiest solution will be doing something like this (considering you are not calling the method from the MainPage class itself.
Frame rootFrame = Window.Current.Content as Frame;
MainPage mainPage = rootFrame.Content as MainPage;
if(mainPage != null)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync
(
Windows.UI.Core.CoreDispatcherPriority.Normal,
() => { mainPage.HideCancelButton(); }
);
}
Upvotes: 2