class 在 windows phone 8.1 中的折叠网格可见性
Collapsed Grid visibility from class in windows phone 8.1
我目前正在使用 windows phone 8.1 [RT] 应用程序,在我的应用程序中,我对 class 隐藏了网格可见性。
为此,我在 cs 页面
上创建了一个 public 方法
public void HideCancelButton()
{
grdCancle.Visibility = Visibility.Collapsed;
bdrCancel.Visibility = Visibility.Collapsed;
Debug.WriteLine("hide button");
//UpdateLayout();
}
并在 helperClass.cs
中按以下方式调用该方法
MainPage mypage = new MainPage();
mypage.HideCancelButton();
它将调试 "hide button" 但不会隐藏网格
我也用过
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>{});
它不会隐藏网格,因为您没有引用当前显示的 MainPage。
无论您在哪里调用 HideCancelButton 方法,您都应该获得对主页的引用。
在你的情况下,最简单的解决方案是做这样的事情(考虑到你不是从 MainPage class 本身调用方法。
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(); }
);
}
我目前正在使用 windows phone 8.1 [RT] 应用程序,在我的应用程序中,我对 class 隐藏了网格可见性。 为此,我在 cs 页面
上创建了一个 public 方法public void HideCancelButton()
{
grdCancle.Visibility = Visibility.Collapsed;
bdrCancel.Visibility = Visibility.Collapsed;
Debug.WriteLine("hide button");
//UpdateLayout();
}
并在 helperClass.cs
中按以下方式调用该方法 MainPage mypage = new MainPage();
mypage.HideCancelButton();
它将调试 "hide button" 但不会隐藏网格
我也用过
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>{});
它不会隐藏网格,因为您没有引用当前显示的 MainPage。
无论您在哪里调用 HideCancelButton 方法,您都应该获得对主页的引用。
在你的情况下,最简单的解决方案是做这样的事情(考虑到你不是从 MainPage class 本身调用方法。
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(); }
);
}