HypernovaDesktop Components · docs
Binarymission
WPF › Control Visual Sizer

Control Visual Sizer

.NET Framework 4.8.NET 6 / 8 / 10v3.0.0WPF

A container that lets the user resize whatever it holds at run time, by dragging a grip in its bottom-right corner, as a window or a text box with a sizing handle is resized.

5public types
31public members
2namespaces

Assembly

AssemblyBinarymission.WPF.Controls.Containers.ControlVisualReSizer.dll
Root namespaceBinarymission.WPF.Controls.Containers
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10
Depends onSkinning

Overview

Wrap any element in it – a chart, a notes box, an image, a panel on a dashboard or design surface – to let the user make it larger or smaller. The content stretches to fill the container by default, so it follows the new size.

How resizing works

The user drags the grip and the container's bottom-right corner follows the pointer, even outside the container's bounds, until the button is released. The new size is set as the container's FrameworkElement.Width and FrameworkElement.Height, so from then on it keeps that size rather than following its parent's layout; its FrameworkElement.MinWidth, FrameworkElement.MaxWidth and the like still apply, which is the way to bound it. A double click on the grip, or a call to ResetSize, clears that size again. ResizeStarted and ResizeCompleted tell you when a drag begins and ends – to save the new layout, for example.

A resize grows the container to the right and downwards, so place it where it can do so: on a Canvas, or with its FrameworkElement.HorizontalAlignment and FrameworkElement.VerticalAlignment set to Left and Top.

The grip

The grip is a 17-pixel square of dots drawn in GripperBrush. IsGripperVisible hides it, IsGripperEnabled leaves it on show but stops it responding, and ResizerStyle replaces its look entirely. The default style gives the container a minimum size of 17 by 17 logical pixels, so the grip always fits.

Shadow

IsDropShadowEnabled gives the container a drop shadow, which helps a resizable panel read as something that can be picked up and changed.

Getting started

Two resizable panels on a dashboard canvas; the new sizes are saved when a drag ends.

<Window x:Class="Dashboard.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sizer="clr-namespace:Binarymission.WPF.Controls.Containers;assembly=Binarymission.WPF.Controls.Containers.ControlVisualReSizer"
        Title="Dashboard" Width="900" Height="600">

    <Canvas Background="#F4F6F9">
        <sizer:ControlVisualResizer Canvas.Left="20" Canvas.Top="20" Width="420" Height="260"
                                    MinWidth="200" MinHeight="120" MaxWidth="840"
                                    IsDropShadowEnabled="True" Background="White"
                                    ResizeCompleted="OnPanelResized">
            <Image Source="Images/monthly-sales.png" Stretch="Uniform" />
        </sizer:ControlVisualResizer>

        <sizer:ControlVisualResizer Canvas.Left="460" Canvas.Top="20" Width="280" Height="200"
                                    IsDropShadowEnabled="True" DropShadowDepth="2" DropShadowOpacity="0.4"
                                    Background="White" GripperBrush="SteelBlue">
            <TextBox AcceptsReturn="True" TextWrapping="Wrap" Text="Notes for the board meeting" />
        </sizer:ControlVisualResizer>
    </Canvas>
</Window>

The handler, and a resizer built in code.

using System;
using System.Windows;
using System.Windows.Controls;
using Binarymission.WPF.Controls.Containers;

private void OnPanelResized(object sender, EventArgs e)
{
    ControlVisualResizer panel = (ControlVisualResizer)sender;
    Properties.Settings.Default.SalesPanelSize = new Size(panel.Width, panel.Height);
    Properties.Settings.Default.Save();
}

ControlVisualResizer notes = new ControlVisualResizer
{
    Width = 280,
    Height = 200,
    MinWidth = 160,
    MinHeight = 100,
    IsDropShadowEnabled = true,
    Content = new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap }
};
Canvas.SetLeft(notes, 40);
Canvas.SetTop(notes, 300);
dashboardCanvas.Children.Add(notes);

API reference

Binarymission.WPF.Controls.Containers

class ControlVisualResizerA container that lets the user resize whatever it holds at run time, by dragging a grip in its bottom-right corner, as a window or a text box with a sizing handle is resized.
enum DirectionThe ways a drag on the grip of a ControlVisualResizer can resize it.
class ResizerGripElementAlignmentConverterTurns a Direction into the alignment that places the resize grip in the right corner of a ControlVisualResizer.
class ResizerGripElementCursorConverterTurns a Direction into the mouse pointer shown over the resize grip of a ControlVisualResizer.

Binarymission.WPF.Controls.Containers.SharedResources

class ControlVisualResizerThemeResourcesThe resource keys of the brushes ControlVisualResizer is drawn with, so that an application can recolour every resizer at once from its own resources.