RectangleGeometry Width, WPF.
IMultiValueConverter, : fooobar.com/questions/134279/...
, ( , Border.Fill ).
:
<Grid>
<Border x:Name="canvasBorder" CornerRadius="5">
<Border.Resources>
<tools:ContentClipConverter x:Key="ContentClipConverter" />
</Border.Resources>
<Border.Clip>
<MultiBinding Converter="{StaticResource ContentClipConverter}">
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource Self}"/>
<Binding Path="ActualHeight"
RelativeSource="{RelativeSource Self}"/>
<Binding Path="CornerRadius"
RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Border.Clip>
</Border>
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Background="Transparent" IsHitTestVisible="false" />
</Grid>
ContentClipConverter.cs:
public class ContentClipConverter : IMultiValueConverter {
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
if (values.Length == 3 && values[0] is double && values[1] is double && values[2] is CornerRadius) {
var width = (double)values[0];
var height = (double)values[1];
if (width < double.Epsilon || height < double.Epsilon) {
return Geometry.Empty;
}
var radius = (CornerRadius)values[2];
var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
clip.Freeze();
return clip;
}
return DependencyProperty.UnsetValue;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) {
throw new NotSupportedException();
}