Silverlight 2.0 beta2 自定义控件调用方法
Page.xaml:
<UserControl x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:XXX ="clr-namespace:SilverlightApplication1"
Width="400" Height="300"> <!--SilverlightApplication1是自定义控件所在项目命名空间-->
<Grid x:Name="LayoutRoot" Background="White">
<XXX:SilverlightControl1 x:Name="UserControl1" Visibility="Visible"></XXX:SilverlightControl1>
<!--SilverlightControl1是自定义控件class名,UserControl1是引用自定义控件后所取的别名,程序中就可以用此别名来控制-->
<Button x:Name="BtnConfirm" Width="200" Height="100" Background="Blue" Content="确 定" Click="BtnConfirm_Click"></Button>
</Grid>
</UserControl>
Page.xaml.cs:
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
{
//控制自定义控件的显示隐藏
if (UserControl1.Visibility == Visibility.Visible)
UserControl1.Visibility = Visibility.Collapsed;
else
UserControl1.Visibility = Visibility.Visible;
}