Binding the Silverlight's Border.Clip RectangleGeometry.Rect property
I have the following XAML:
<Border x:Name="ClippingBorder" VerticalAlignment="Stretch" BorderThickness="0">
<Border.Clip>
<RectangleGeometry RadiusX="4.4" RadiusY="4.4" Rect="{Binding ClippingRectangle}"/>
</Border.Clip>
</Border>
And the following codebehind:
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);
}
The resize works, but unfortunately the clipping is not working in that the rounded corners are not rounded. If I substitute the ClippingRectangle binding for static values it works. But when I use the binding it does not. Is there a solution for this?
You can still bind from XAML with the code below:
private RectangleGeometry clippingRectangleGeometry;
public RectangleGeometry ClippingRectangleGeometry
{
get
{
return clippingRectangleGeometry;
}
set
{
clippingRectangleGeometry= value;
NotifyPropertyChanged("ClippingRectangleGeometry");
}
}
It turns out that setting the Border.Clip property in the codebehind resolves the issue.
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;
}
精彩评论