这种效果很常见的,就是当用户点击页面上某个选项或按钮,弹出一个窗口,同时窗口其他部分用半透明色给遮罩起来,不允许编辑.
用Silverlight做了一个,写下来总结一下:
1.新建一个NewWindow.xaml文件,默认代码如下:
<
UserControl x:Class
=
"
SilverlightDemo.DetailView
"
xmlns
=
"
http://schemas.microsoft.com/client/2007
"
xmlns:x
=
"
http://schemas.microsoft.com/winfx/2006/xaml
"
>
<
Grid
>
</
Grid
>
</
UserControl
>
2.在Grid中添加一个
Rectangle,并设置Opacity(透明度)和Fill(填充色)属性,形如下:
<
Rectangle Opacity
=
"
0.8
"
Fill
=
"
LightGray
"
/>
3.然后下面的内容就是要显示的东西了,我这里让他显示一个TextBlock和一个关闭按钮,形如下:
<
Border CornerRadius
=
"
30
"
Background
=
"
#ff5c7890
"
Width
=
"
600
"
Height
=
"
250
"
>
<
StackPanel
>
<
Grid Margin
=
"
30
"
>
<
TextBlock Text
=
"
{Binding FirstName}
"
Foreground
=
"
White
"
FontSize
=
"
20
"
/>
<
Button Content
=
"
close
"
Click
=
"
Button_Click
"
Width
=
"
50
"
Height
=
"
30
"
/>
</
Grid
>
</
StackPanel
>
</
Border
>
4.关闭按钮的Click方法如下,也就是设置Visibility的值而已.形如下:
private void Button_Click(object sender, RoutedEventArgs e)
{
Visibility = Visibility.Collapsed;
}
5.OK,NewWindow.xaml文件就到这里,下面只要在需要遮罩的文件中使用就可以了,我这里是在page.xaml文件中单击按钮是弹出遮罩.所以:
首先,引入命名空间,具体的要看你的项目,我这里是:
xmlns:app
=
"
clr-namespace:SilverlightDemo
"
然后直接在page.xaml页面中插入自定义控件NewWindow,记得设置属性Visibility为Collapsed,让他在页面载入时是不弹出来的.形如下:
<
app:DetailView x:Name
=
"
detailView
"
Grid.RowSpan
=
"
2
"
Visibility
=
"
Collapsed
"
/>
然后在按钮的Click事件中把Visibility值设置成
Visible就可以了.形如下:
private void Button1_OnClick(object sender, RoutedEventArgs e){
detailView.Visibility
=
Visibility.Visible;
}
啰啰嗦嗦的讲了一堆,其实就是很简单的问题.呵呵!