Bodenberg.AppDimens.Sdps.Wpf
3.6.1
dotnet add package Bodenberg.AppDimens.Sdps.Wpf --version 3.6.1
NuGet\Install-Package Bodenberg.AppDimens.Sdps.Wpf -Version 3.6.1
<PackageReference Include="Bodenberg.AppDimens.Sdps.Wpf" Version="3.6.1" />
<PackageVersion Include="Bodenberg.AppDimens.Sdps.Wpf" Version="3.6.1" />
<PackageReference Include="Bodenberg.AppDimens.Sdps.Wpf" />
paket add Bodenberg.AppDimens.Sdps.Wpf --version 3.6.1
#r "nuget: Bodenberg.AppDimens.Sdps.Wpf, 3.6.1"
#:package Bodenberg.AppDimens.Sdps.Wpf@3.6.1
#addin nuget:?package=Bodenberg.AppDimens.Sdps.Wpf&version=3.6.1
#tool nuget:?package=Bodenberg.AppDimens.Sdps.Wpf&version=3.6.1
Bodenberg.AppDimens.Sdps.Wpf
📖 Documentation: Bodenberg.AppDimens.Sdps.Wpf guide · complete API reference · all AppDimens .NET packages
Responsive sizes for WPF. Write {sdps:Sdp 16} instead of 16 and your margins, buttons and
text grow on big windows and shrink on small ones — automatically, while the user resizes the
window or drags it to another monitor.
Same engine as Bodenberg.AppDimens.Maui.Sdps
(Android sdp/ssp parity), packaged for WPF with no .NET MAUI dependency.
| Frameworks | net8.0-windows, net9.0-windows, net10.0-windows (+ net11.0-windows with SDK 11) |
| Works with | Any WPF app (<UseWPF>true</UseWPF>), any monitor DPI |
| License | Apache-2.0 |
Table of contents
- How it works (30-second version)
- Step 1 — Install
- Step 2 — Initialize (one line)
- Step 3 — Use it in XAML
- Step 4 — Use it in C#
- Complete example window
- Which function should I use?
- Styles, templates and resources
- Bindings with numbers from your ViewModel
- Advanced options
- Troubleshooting
- Português (resumo)
How it works (30-second version)
- You keep designing with the numbers you already know (
16for padding,14for text…). - AppDimens treats those numbers as sizes on a 300-unit-wide reference screen and scales them to the
current window: when the window's smaller side is 600 units,
{sdps:Sdp 16}becomes about32. - WPF units are device-independent (1/96 inch), so the result is already correct on 100 %, 150 % or 200 % DPI.
- When the window is resized, every
{sdps:...}value is recalculated automatically.
Step 1 — Install
Visual Studio: right-click your WPF project → Manage NuGet Packages… → Browse → search
Bodenberg.AppDimens.Sdps.Wpf → Install.
Command line:
dotnet add package Bodenberg.AppDimens.Sdps.Wpf
Step 2 — Initialize (one line)
Open MainWindow.xaml.cs and add one line before InitializeComponent():
using System.Windows;
using AppDimens.Sdps.Wpf;
namespace MyApp;
public partial class MainWindow : Window
{
public MainWindow()
{
AppDimensWpf.Initialize(this); // ← sizes now follow THIS window
InitializeComponent();
}
}
💡 Forgot this line? It still works — the values use the screen size instead of the window size and do not follow window resizes.
Step 3 — Use it in XAML
- Add the namespace to the root element of your XAML file:
xmlns:sdps="clr-namespace:AppDimens.Sdps.Wpf;assembly=AppDimens.Sdps.Wpf"
- Replace fixed numbers with
{sdps:Function Number}:
<Button Width="120" Height="40" Margin="16" FontSize="14" Content="Save" />
<Button Width="{sdps:Sdp 120}"
Height="{sdps:Hdp 40}"
Margin="{sdps:Sdp 16}"
FontSize="{sdps:Ssp 14}"
Content="Save" />
Margin, Padding, CornerRadius, BorderThickness and Grid row/column sizes are converted
automatically — Margin="{sdps:Sdp 16}" means 16 on all four sides.
Step 4 — Use it in C#
using AppDimens.Sdps.Wpf; // 16.Sdp(), 14.Ssp() …
myButton.Width = 120.Sdp();
myButton.Margin = new Thickness(16.Sdp());
myTitle.FontSize = 20.Ssp();
Values set from code are not updated automatically. Re-apply them when the window changes:
using AppDimens.Sdps.Wpf;
AppDimensWpf.Changed += (_, _) => ApplySizes();
void ApplySizes()
{
myButton.Width = 120.Sdp();
myTitle.FontSize = 20.Ssp();
}
Complete example window
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sdps="clr-namespace:AppDimens.Sdps.Wpf;assembly=AppDimens.Sdps.Wpf"
Title="AppDimens demo" Width="900" Height="600">
<Grid Margin="{sdps:Sdp 16}">
<Grid.RowDefinitions>
<RowDefinition Height="{sdps:Hdp 56}" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{sdps:Wdp 200}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="2" Text="Dashboard"
FontSize="{sdps:Ssp 22}" VerticalAlignment="Center" />
<StackPanel Grid.Row="1">
<Button Content="Home" Margin="{sdps:Sdp 4}" Padding="{sdps:Sdp 8}" FontSize="{sdps:Ssp 14}" />
<Button Content="Settings" Margin="{sdps:Sdp 4}" Padding="{sdps:Sdp 8}" FontSize="{sdps:Ssp 14}" />
</StackPanel>
<Border Grid.Row="1" Grid.Column="1" Background="#EEE"
CornerRadius="{sdps:Sdp 12}" Padding="{sdps:Sdp 16}">
<TextBlock TextWrapping="Wrap" FontSize="{sdps:Ssp 14}"
Text="Resize the window: every size above is recalculated." />
</Border>
</Grid>
</Window>
Which function should I use?
| I want to size… | Use | Example |
|---|---|---|
| Padding, margins, icons, cards — most cases | Sdp (follows the smaller side of the window) |
{sdps:Sdp 16} |
| Things that follow the window height (header, toolbar) | Hdp |
{sdps:Hdp 56} |
| Things that follow the window width (side menu, banner) | Wdp |
{sdps:Wdp 200} |
| Text | Ssp |
{sdps:Ssp 14} |
| Text by height / width | Hsp / Wsp |
{sdps:Hsp 18} |
| Text that ignores the user font scale | Sem, Hem, Wem |
{sdps:Sem 12} |
| Slightly bigger on very wide/tall windows | add a: Sdpa, Sspa, Hspa… |
{sdps:Sdpa 16} |
| A size that must stay fixed after startup (does not follow resizes) | add i: Sdpi, Hdpi, Wdpi, Sspi… |
{sdps:Sdpi 16} |
All 30 functions are available as {sdps:Name value} in XAML, as value.Name() in C#, and as
DimenFunction.Name for converters.
Styles, templates and resources
Markup works inside styles and templates too, and stays live:
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="{sdps:Sdp 4}" />
<Setter Property="Padding" Value="{sdps:Sdp 8}" />
<Setter Property="FontSize" Value="{sdps:Ssp 14}" />
</Style>
</Window.Resources>
Bindings with numbers from your ViewModel
DimenConverter scales a bound number:
<Window.Resources>
<sdps:DimenConverter x:Key="Sdp" Function="Sdp" />
</Window.Resources>
<Border Width="{Binding CardWidth, Converter={StaticResource Sdp}}" />
<TextBlock FontSize="{Binding TitleSize, Converter={StaticResource Sdp}, ConverterParameter=Ssp}" />
Advanced options
| Property / API | What it does |
|---|---|
Live="False" |
Computes the value once (no binding): {sdps:Sdp 16, Live=False} |
As="Thickness" |
Forces the output type (Double, Thickness, CornerRadius, GridLength) |
AppDimensWpf.Initialize(window, options) |
new AppDimensOptions { ScalingMode = ScalingMode.Continuous } for smooth (non-bucket) scaling |
AppDimensWpf.Refresh() |
Re-reads the window size manually |
AppDimensWpf.Detach() |
Stops tracking the window |
AppDimensSdps.CaptureBaseline() |
Re-freezes the baseline used by the *i functions |
AppDimensSdps.Resolver.SetFontScale(1.2f) |
Applies an app-level text zoom to Ssp/Hsp/Wsp |
Troubleshooting
| Problem | Fix |
|---|---|
The name "Sdp" does not exist in namespace |
Check the xmlns:sdps="clr-namespace:AppDimens.Sdps.Wpf;assembly=AppDimens.Sdps.Wpf" line. Rebuild once. |
| Values do not change when resizing | Call AppDimensWpf.Initialize(this) in the window constructor. Values set from C# must be re-applied in AppDimensWpf.Changed. |
| Everything looks too big on a large monitor | Use Sdp for most things (it follows the smaller side). Use Wdp/Hdp only where you want width/height scaling. |
| I want the old fixed value for one control | Just keep the plain number — you can mix fixed and scaled values. |
Português (resumo)
- Instale:
dotnet add package Bodenberg.AppDimens.Sdps.Wpf - No construtor da janela, antes de
InitializeComponent():AppDimensWpf.Initialize(this); - No XAML adicione
xmlns:sdps="clr-namespace:AppDimens.Sdps.Wpf;assembly=AppDimens.Sdps.Wpf"e troque números fixos por{sdps:Sdp 16}(margens/tamanhos),{sdps:Ssp 14}(texto),{sdps:Hdp 56}(altura),{sdps:Wdp 200}(largura). - Em C#:
botao.Width = 120.Sdp();e, para atualizar ao redimensionar, useAppDimensWpf.Changed += ....
Os valores do XAML se atualizam sozinhos quando a janela muda de tamanho ou de monitor.
Links: Repository · MAUI version · Android library
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0-windows was computed. net10.0-windows7.0 is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.6.1 | 81 | 10/12/2026 |