ClipRect.DefiningGeometry
ndClipRect.RenderedGeometry
仅包含RadiusX
andRadiusY
值,但不包含 also 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>