Skip to content

Commit 3fb064b

Browse files
feat: min/max height & width
1 parent 74e68b7 commit 3fb064b

4 files changed

Lines changed: 79 additions & 3 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ Window size:
6363
```csharp
6464
builder.Window
6565
.UseWidth(1920)
66-
.UseHeight(1080);
66+
.UseHeight(1080)
67+
.UseMinWidth(1280)
68+
.UseMinHeight(720);
69+
.UseMaxWidth(2560)
70+
.UseMaxHeight(1440);
6771
```
6872

6973
Disable window resizing:
@@ -86,8 +90,12 @@ It is also possible to configure these values through `appsettings.json` like so
8690
{
8791
"Window": {
8892
"Title": "Hello Blazor",
89-
"Height": 900,
90-
"Width": 400,
93+
"Height": 1080,
94+
"Width": 1920,
95+
"MinHeight": 720,
96+
"MinWidth": 1280,
97+
"MaxHeight": 1440,
98+
"MaxWidth": 2560,
9199
"Frame": false,
92100
"Resizable": false,
93101
"Icon": "hello.ico"

src/BlazorDesktop/Hosting/ConfigureWindowBuilder.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,50 @@ public ConfigureWindowBuilder UseWidth(int width)
5656
return this;
5757
}
5858

59+
/// <summary>
60+
/// Uses a specific min height for the window.
61+
/// </summary>
62+
/// <param name="minHeight">The min height.</param>
63+
/// <returns>The <see cref="ConfigureWindowBuilder"/>.</returns>
64+
public ConfigureWindowBuilder UseMinHeight(int minHeight)
65+
{
66+
_configuration[WindowDefaults.MinHeight] = minHeight.ToString();
67+
return this;
68+
}
69+
70+
/// <summary>
71+
/// Uses a specific min width for the window.
72+
/// </summary>
73+
/// <param name="minWidth">The min width.</param>
74+
/// <returns>The <see cref="ConfigureWindowBuilder"/>.</returns>
75+
public ConfigureWindowBuilder UseMinWidth(int minWidth)
76+
{
77+
_configuration[WindowDefaults.MinWidth] = minWidth.ToString();
78+
return this;
79+
}
80+
81+
/// <summary>
82+
/// Uses a specific max height for the window.
83+
/// </summary>
84+
/// <param name="maxHeight">The max height.</param>
85+
/// <returns>The <see cref="ConfigureWindowBuilder"/>.</returns>
86+
public ConfigureWindowBuilder UseMaxHeight(int maxHeight)
87+
{
88+
_configuration[WindowDefaults.MaxHeight] = maxHeight.ToString();
89+
return this;
90+
}
91+
92+
/// <summary>
93+
/// Uses a specific max width for the window.
94+
/// </summary>
95+
/// <param name="maxWidth">The max width.</param>
96+
/// <returns>The <see cref="ConfigureWindowBuilder"/>.</returns>
97+
public ConfigureWindowBuilder UseMaxWidth(int maxWidth)
98+
{
99+
_configuration[WindowDefaults.MaxWidth] = maxWidth.ToString();
100+
return this;
101+
}
102+
59103
/// <summary>
60104
/// If the window should have a frame.
61105
/// </summary>

src/BlazorDesktop/Hosting/WindowDefaults.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ public static class WindowDefaults
2424
/// </summary>
2525
public static readonly string Width = "window:width";
2626

27+
/// <summary>
28+
/// The configuration key associated with the min height.
29+
/// </summary>
30+
public static readonly string MinHeight = "window:minHeight";
31+
32+
/// <summary>
33+
/// The configuration key associated with the min width.
34+
/// </summary>
35+
public static readonly string MinWidth = "window:minWidth";
36+
37+
/// <summary>
38+
/// The configuration key associated with the max height.
39+
/// </summary>
40+
public static readonly string MaxHeight = "window:maxHeight";
41+
42+
/// <summary>
43+
/// The configuration key associated with the max width.
44+
/// </summary>
45+
public static readonly string MaxWidth = "window:maxWidth";
46+
2747
/// <summary>
2848
/// The configuration key associated with the frame.
2949
/// </summary>

src/BlazorDesktop/Wpf/BlazorDesktopWindow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ private void InitializeWindow()
101101
Title = _config.GetValue<string?>(WindowDefaults.Title) ?? _environment.ApplicationName;
102102
Height = _config.GetValue<int?>(WindowDefaults.Height) ?? 768;
103103
Width = _config.GetValue<int?>(WindowDefaults.Width) ?? 1366;
104+
MinHeight = _config.GetValue<int?>(WindowDefaults.MinHeight) ?? 0;
105+
MinWidth = _config.GetValue<int?>(WindowDefaults.MinWidth) ?? 0;
106+
MaxHeight = _config.GetValue<int?>(WindowDefaults.MaxHeight) ?? 0;
107+
MaxWidth = _config.GetValue<int?>(WindowDefaults.MaxWidth) ?? 0;
104108
UseFrame(_config.GetValue<bool?>(WindowDefaults.Frame) ?? true);
105109
ResizeMode = (_config.GetValue<bool?>(WindowDefaults.Resizable) ?? true) ? ResizeMode.CanResize : ResizeMode.NoResize;
106110
UseIcon(_config.GetValue<string?>(WindowDefaults.Icon) ?? string.Empty);

0 commit comments

Comments
 (0)