Skip to content

Commit c0946bf

Browse files
committed
Add FlexPanel overview to "Readme.md"
1 parent 86ec31c commit c0946bf

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,94 @@ Example of usage:
127127
</Page>
128128

129129
```
130+
131+
132+
## FlexPanel
133+
134+
**FlexPanel** is a layout panel similar to `StackPanel`, but with additional control over how children are spaced and aligned. It supports a layout model inspired by CSS Flexbox, making it easier to create clean, consistent UIs without extra nesting or manual margin tweaking.
135+
136+
#### Key features
137+
138+
- **Orientation**
139+
Arrange children in a `Horizontal` or `Vertical` layout using the `Orientation` property, just like with `StackPanel`.
140+
141+
- **Justify**
142+
Controls how space is distributed along the main axis. Options include:
143+
- `Start`
144+
- `Center`
145+
- `End`
146+
- `SpaceBetween`
147+
- `SpaceAround`
148+
- `SpaceEvenly`
149+
- `SpaceAuto`
150+
151+
- **Align**
152+
Controls alignment along the cross axis.
153+
Unlike `StackPanel`, where you typically set `HorizontalAlignment` or `VerticalAlignment` on each child, `FlexPanel` allows you to control all children’s alignment from the panel itself using the `Align` property.
154+
155+
- **Simplified layout**
156+
Ideal for toolbars, button groups, or dashboards where you want consistent spacing and alignment without relying on `Grid` or setting margins manually.
157+
158+
#### Things to know
159+
160+
- **Child `Margin` is currently ignored**
161+
Spacing is handled entirely by the panel based on the `Justify` setting. Margins set on individual children will not affect layout.
162+
163+
- **Children are arranged using their natural `DesiredSize`**
164+
There is currently no support for stretching or shrinking children to fill space (no equivalent of `flex-grow` or `flex-shrink`).
165+
166+
- **No wrapping support**
167+
Children are arranged in a single row or column only. If you need wrapping behavior, use a `WrapPanel` instead.
168+
169+
- **Simplified alignment options**
170+
`Align` currently supports only `Start`, `Center`, and `End`. More advanced options like `baseline` or `stretch` are not implemented yet.
171+
172+
- **AddHeight property**
173+
Adds extra vertical space to the layout, useful when additional height is needed beyond what the children require.
174+
175+
This panel is useful in scenarios where `StackPanel` is too limited, but using a `Grid` would add unnecessary complexity.
176+
177+
![Screenshot of the FlexPanel](docs/images/FlexPanel_Screenshot1.png)
178+
179+
Example of usage:
180+
181+
```xml
182+
<Page
183+
x:Class="TestApp.TestAnimatedNavigationBar"
184+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
185+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
186+
xmlns:controlskit="clr-namespace:OpenSilver.ControlsKit;assembly=OpenSilver.ControlsKit.Controls">
187+
188+
<StackPanel Orientation="Vertical">
189+
190+
<TextBlock Style="{StaticResource SubTitleStyle}" Text="??????? Justify - SpaceAround" />
191+
<controlskit:FlexPanel Justify="SpaceAround" Orientation="Vertical">
192+
<Grid Width="50" Height="50" Background="Red" />
193+
<Grid Width="50" Height="50" Background="Green" />
194+
<Grid Width="50" Height="50" Background="Blue" />
195+
</controlskit:FlexPanel>
196+
197+
<TextBlock Style="{StaticResource SubTitleStyle}" Text="????????? Justify - SpaceAuto" />
198+
<controlskit:FlexPanel Justify="SpaceAuto" Orientation="Vertical">
199+
<Grid Width="50" Height="50" Background="Red" />
200+
<Grid Width="50" Height="50" Background="Green" />
201+
<Grid Width="50" Height="50" Background="Blue" />
202+
</controlskit:FlexPanel>
203+
204+
<TextBlock Style="{StaticResource SubTitleStyle}" Text="???????? Justify - SpaceEvenly" />
205+
<controlskit:FlexPanel Align="Center" Justify="SpaceEvenly" Orientation="Vertical">
206+
<Grid Width="50" Height="50" ackground="Red" />
207+
<Grid Width="50" Height="50" Background="Green" />
208+
<Grid Width="50" Height="50" Background="Blue" />
209+
</controlskit:FlexPanel>
210+
211+
<TextBlock Style="{StaticResource SubTitleStyle}" Text="??????? Justify - SpaceBetween" />
212+
<controlskit:FlexPanel Align="Center" Justify="SpaceBetween" Orientation="Vertical">
213+
<Grid Width="50" Height="50" Background="Red" />
214+
<Grid Width="50" Height="50" Background="Blue" />
215+
</controlskit:FlexPanel>
216+
217+
</StackPanel>
218+
</Page>
219+
220+
```
19.8 KB
Loading

0 commit comments

Comments
 (0)