我需要访问 Windows 8 Metro 应用程序中用户控件(子页面)中的主页值。请告诉我该怎么做?
在子页面中,我试图访问这样的主页控件:
DealersPage main = new DealersPage();
Grid grd = main.FindName("visibleGrid") as Grid;
grd.Visibility = Visibility.Collapsed;
但没有运气!!!请告诉我
编辑:在图像点击事件的子页面(用户控件)中,我写了下面的代码。
private void imgClose_Tapped(object sender, TappedRoutedEventArgs e)
{
DealersPage main = this.Parent as DealersPage;
if (main != null)
{
Grid grd = main.FindName("visibleGrid") as Grid;
grd.Visibility = Visibility.Collapsed;
}
settingsControl.Visibility = Visibility.Collapsed;
}
在 MainPage (DealersPage) 我的设计是这样的:
<Grid HorizontalAlignment="Left" Height="758" Margin="0,10,0,0" VerticalAlignment="Top" Width="1366" x:Name="visibleGrid" Opacity="0.85" Background="#FF858585">
<Grid HorizontalAlignment="Left" Height="600" Margin="454,108,0,0" Visibility="Collapsed" VerticalAlignment="Top" Width="500" x:Name="gridpopup">
<local:Settings x:Name="SettingsUsercontrol" Visibility="Collapsed" Height="600" Width="500"/>
</Grid>
</Grid>