您可以使用LinearGradientBrush作爲控件的OpacityMask,並將偏移量綁定到控件的ActualHeight,然後從該值中減去25並將其除以ActualHeight以獲取以%爲單位的值。這應該給你25像素的透明部分在底部
<WebBrowser Name="webBrowser">
<WebBrowser.OpacityMask>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FFFF0000"
Offset="{Binding ElementName=webBrowser,
Path=ActualHeight,
Converter={StaticResource OffsetConverter},
ConverterParameter=25}"/>
<GradientStop Color="#00000000"
Offset="{Binding ElementName=webBrowser,
Path=ActualHeight,
Converter={StaticResource OffsetConverter},
ConverterParameter=25}"/>
</LinearGradientBrush>
</WebBrowser.OpacityMask>
</WebBrowser>
的OffsetConverter
public class OffsetConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double height = (double)value;
double subract = System.Convert.ToDouble(parameter.ToString());
double opacityMaskHeight = height - subract;
return opacityMaskHeight/height;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
啊就像一個魅力,非常感謝你! – Tiax 2010-12-12 16:41:03