在我的应用程序中有一个侧边栏,它持有这两个组件:
<Grid x:Name="AF" Visibility="Visibility">
<betata:AForm Height="508" VerticalAlignment="Top"/>
</Grid>
<Grid x:Name="AR" Visibility="Collapsed">
<betata:AReg Height="508" VerticalAlignment="Top"/>
</Grid>
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
betata.Views.Sidebar.Sidebar sd = new Sidebar();
sd.showAR(this);
}
回到我的侧边栏代码得到了另一个名为showAR的方法,具有以下功能:
public void showAR(AForm aForm)
{
this.AR.Visibility = Visibility.Visible;
aForm.Visibility = Visibility.Collapsed;
}
但我不确定为什么aForm会崩溃,但AR无法显现。
答案 0 :(得分:1)
我会稍微重构一下,使其更简单(这可能有助于解决您的问题)。
<Grid>
<betat:AForm x:Name="aForm" Height="508" VerticalAlignment="Top" Visibility="Visible" />
<betata:AReg x:Name="aReg" Height="508" VerticalAlignment="Top" Visibility="Collapsed" />
</Grid>
public void showAR() // this is in the code behind (xaml.cs) of the Sidebar UserControl
{
this.aReg.Visibility = Visibility.Visible;
this.aForm.Visibility = Visibility.Collapsed;
}
或者您甚至不需要ShowAR(),只需在按钮单击中设置可见性,除非您在其他地方重复使用该功能。例如:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
betata.Views.Sidebar.Sidebar sd = new Sidebar();
sd.aReg.Visibility = Visibility.Visible;
sd.aForm.Visibility = Visibility.Collapsed;
}
答案 1 :(得分:1)
这篇文章已经回答了问题。 Visibility of User Control可以通过隧道和冒泡来解决。这是Silverlight的新路由事件功能