VisualElementHostSizeConverter
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 | |
|---|---|
Convert | Builds the clip shape for an element of the given size and corner radius. |
ConvertBack | Not supported: a clip shape cannot be turned back into a size and radius. |
Methods
Convert
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, itsCornerRadius. 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
Geometryof 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: aRectof that size at 0,0. - With
null, fewer than two values, or a width or height that is not adouble: the integer0, which is not a usable clip, so the binding falls back to no clip at all.
ConvertBack
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.