HypernovaDesktop Components · docs
Binarymission
WPF › Rounded Corner Container › VisualElementHostSizeConverter

VisualElementHostSizeConverter

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Containers

Turns a bound width, height and, optionally, a CornerRadius into the shape that RoundedCornerContainer clips its content to.

public class VisualElementHostSizeConverter : IMultiValueConverter

Inherits from / implements: IMultiValueConverter

Remarks

The container's default template uses it in a MultiBinding on the clip of its outer border. It is public so that a template of your own can do the same, which is what lets the corner radius reach the clip: a radius bound on a geometry directly is never applied, because a geometry is not in the element tree for the binding to find its source.

Give it two values (width and height) for a plain Rect of that size, or three (width, height and corner radius) for a rounded Geometry with each corner its own radius.

Examples

<Border x:Name="Frame" CornerRadius="{TemplateBinding CornerRadius}">
    <Border.Resources>
        <rc:VisualElementHostSizeConverter x:Key="ClipShape" />
    </Border.Resources>
    <Border.Clip>
        <MultiBinding Converter="{StaticResource ClipShape}">
            <Binding Path="ActualWidth"  RelativeSource="{RelativeSource Self}" />
            <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
            <Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
        </MultiBinding>
    </Border.Clip>
    <ContentPresenter />
</Border>

See also

Members at a glance

Methods
ConvertBuilds the clip shape for an element of the given size and corner radius.
ConvertBackNot supported: a clip shape cannot be turned back into a size and radius.

Methods

Convert

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)

Builds the clip shape for an element of the given size and corner radius.

Parameters
values
The element's width and height in logical pixels, both double, and optionally a third value, its CornerRadius.
targetType
The type the binding target expects. Not used.
parameter
Not used.
culture
Not used.
Returns
  • With a width, a height and a corner radius: a Geometry of that size whose corners are rounded. Each radius is brought within half the shorter side, and a negative radius gives a square corner. The geometry is frozen.
  • With a width and a height only, or a third value that is not a CornerRadius: a Rect of that size at 0,0.
  • With null, fewer than two values, or a width or height that is not a double: the integer 0, which is not a usable clip, so the binding falls back to no clip at all.

ConvertBack

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)

Not supported: a clip shape cannot be turned back into a size and radius.

Parameters
value
Not used.
targetTypes
Not used.
parameter
Not used.
culture
Not used.
Returns

Never returns.

Exceptions
System.NotImplementedException
Always.