我有以下XAML:
<Border x:Name="ClippingBorder" VerticalAlignment="Stretch" BorderThickness="0">
<Border.Clip>
<RectangleGeometry RadiusX="4.4" RadiusY="4.4" Rect="{Binding ClippingRectangle}"/>
</Border.Clip>
</Border>
以下代码隐藏:
private Rect clippingRectangle;
public Rect ClippingRectangle
{
get
{
return clippingRectangle;
}
set
{
clippingRectangle = value;
NotifyPropertyChanged("ClippingRectangle");
}
}
public MainPage()
{
InitializeComponent();
//Get the actual height of the content frame
ClippingBorder.DataContext = this;
ContentFrame.SizeChanged += new SizeChangedEventHandler(ContentFrame_SizeChanged);
}
void ContentFrame_SizeChanged(object sender, SizeChangedEventArgs e)
{
MessageBox.Show(e.NewSize.Height.ToString());
ClippingRectangle = new Rect(0,0,798,e.NewSize.Height);
}
调整大小有效,但不幸的是裁剪不起作用,圆角不圆。如果我用ClippingRectangle绑定替换静态值,它就可以工作。但是,当我使用绑定时,它没有。有解决方案吗?
答案 0 :(得分:2)
您仍然可以使用以下代码从XAML绑定:
private RectangleGeometry clippingRectangleGeometry;
public RectangleGeometry ClippingRectangleGeometry
{
get
{
return clippingRectangleGeometry;
}
set
{
clippingRectangleGeometry= value;
NotifyPropertyChanged("ClippingRectangleGeometry");
}
}
答案 1 :(得分:0)
事实证明,在代码隐藏中设置Border.Clip属性可以解决问题。
void ContentFrame_SizeChanged(object sender, SizeChangedEventArgs e)
{
RectangleGeometry clipRect = new RectangleGeometry();
clipRect.Rect = new Rect(0,0,798,e.NewSize.Height);
clipRect.RadiusX = 4.4;
clipRect.RadiusY = 4.4;
ClippingBorder.Clip = clipRect;
}