ClipRect.DefiningGeometry
nd ClipRect.RenderedGeometry
仅包含RadiusX
和RadiusY
值,但不包括Rect
。
我不知道究竟你要实现(这不是很清楚,我从你的样品)什么,但你可以写一个IValueConverter
这将提取您从引用Rectangle
需要的信息:
public class RectangleToGeometryConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rect = value as Rectangle;
if (rect == null || targetType != typeof(Geometry))
{
return null;
}
return new RectangleGeometry(new Rect(new Size(rect.Width, rect.Height)))
{
RadiusX = rect.RadiusX,
RadiusY = rect.RadiusY
};
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
这样,你会在你的绑定定义中使用该转换器:
<Rectangle Width="100" Height="100"
Clip="{Binding ElementName=ClipRect, Converter={StaticResource RectangleToGeometryConverter}}">
当然,你需要转换器第一次添加到您的资源:
<Window.Resources>
<local:RectangleToGeometryConverter x:Key="RectangleToGeometryConverter" />
</Window.Resources>
看看http://stackoverflow.com/questions/1321740/wpf-how-to-show-only-part-of-big-canvas – 2012-04-09 15:28:57