Skip to content

Commit c74ac39

Browse files
author
eriklimakc
committed
chore: Add csharp markup examples
1 parent 70e35dc commit c74ac39

8 files changed

+924
-150
lines changed

doc/controls/ChipAndChipGroup.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ sealed class ChipRemovingEventArgs : EventArgs
6262
```
6363

6464
### Usage
65+
# [**XAML**](#tab/xaml)
6566
```xml
6667
xmlns:utu="using:Uno.Toolkit.UI"
6768
...
@@ -71,14 +72,38 @@ xmlns:utu="using:Uno.Toolkit.UI"
7172
<utu:Chip Content="Filter Chip" IsChecked="True" Style="{StaticResource FilterChipStyle}" />
7273
<utu:Chip Content="Suggestion Chip" IsChecked="True" Style="{StaticResource SuggestionChipStyle}" />
7374

74-
<!-- with icon -->
75+
<!-- With icon -->
7576
<utu:Chip Content="Chip" Style="{StaticResource MaterialChipStyle}">
7677
<utu:Chip.Icon>
7778
<Image Source="ms-appx:///Assets/Avatar.png" />
7879
</utu:Chip.Icon>
7980
</utu:Chip>
8081
```
81-
82+
# [**C#**](#tab/csharp)
83+
```cs
84+
new Chip()
85+
.Content("Assist Chip")
86+
.Style(Theme.Chip.Styles.Assist),
87+
new Chip()
88+
.Content("Input Chip")
89+
.Style(Theme.Chip.Styles.Input),
90+
new Chip()
91+
.Content("Filter Chip")
92+
.Style(Theme.Chip.Styles.Filter),
93+
new Chip()
94+
.Content("Suggestion Chip")
95+
.Style(Theme.Chip.Styles.Suggestion),
96+
97+
// With icon
98+
new Chip()
99+
.Content("Chip")
100+
.Style(Theme.Chip.Styles.Default)
101+
.Icon(
102+
new Image()
103+
.Source("ms-appx:///Assets/Avatar.png")
104+
)
105+
```
106+
***
82107
## Lightweight Styling
83108

84109
Key|Type|Value
@@ -162,18 +187,29 @@ ElevatedChipBackground|SolidColorBrush|SurfaceBrush
162187
public partial class ChipGroup : ItemsControl
163188
```
164189

165-
### XAML
190+
### Usage
191+
# [**XAML**](#tab/xaml)
166192
```xml
167193
xmlns:utu="using:Uno.Toolkit.UI"
168194
...
169195

170196
<utu:ChipGroup .../>
171197
-or-
172198
<utu:ChipGroup>
173-
oneOrMoreItems
199+
<!-- One or more Items -->
174200
</utu:ChipGroup>
175201
```
202+
# [**C#**](#tab/csharp)
203+
```cs
204+
new ChipGroup()
205+
...
176206

207+
new ChipGroup()
208+
.Items(
209+
// One or more Items
210+
)
211+
```
212+
***
177213
### Inheritance
178214
Object &#8594; DependencyObject &#8594; UIElement &#8594; FrameworkElement &#8594; Control &#8594; ItemsControl &#8594; ChipGroup
179215

@@ -226,7 +262,8 @@ class ChipItemRemovingEventHandler : ChipItemEventHandler
226262
}
227263
```
228264

229-
### Usage
265+
#### Usage
266+
# [**XAML**](#tab/xaml)
230267
```xml
231268
xmlns:utu="using:Uno.Toolkit.UI"
232269
...
@@ -258,3 +295,31 @@ xmlns:utu="using:Uno.Toolkit.UI"
258295
SelectionMode="Multiple"
259296
Style="{StaticResource SuggestionChipGroupStyle}" />
260297
```
298+
# [**C#**](#tab/csharp)
299+
```cs
300+
// example with binding
301+
new ChipGroup()
302+
.ItemsSource(() => vm.ChipsList)
303+
.Style(Theme.ChipGroup.Styles.Suggestion)
304+
.ItemTemplate<ToDoItem>(item => new TextBlock()
305+
.Text(() => item.Name)
306+
),
307+
308+
// single selection with binding
309+
new ChipGroup()
310+
.ItemsSource(() => vm.ChipsList)
311+
.SelectedItem(x => x.Bind(() => vm.SelectedItem).TwoWay())
312+
.SelectionMode(ChipSelectionMode.Single)
313+
.Style(Theme.ChipGroup.Styles.Suggestion),
314+
315+
// multi-selection with binding
316+
new ChipGroup()
317+
.ItemsSource(() => vm.ChipsList)
318+
.SelectedItems(x => x.Bind(() => vm.SelectedItems).TwoWay())
319+
.SelectionMode(ChipSelectionMode.Multiple)
320+
.Style(Theme.ChipGroup.Styles.Suggestion)
321+
```
322+
323+
> [!IMPORTANT]
324+
> ItemClick Event are currently not supported in C# Markup.
325+
***

doc/controls/Divider.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ DividerSubHeaderMargin|Thickness|0,4,0,0
2424
DividerHeight|Double|1
2525

2626
## Usage
27+
# [**XAML**](#tab/xaml)
2728
```xml
2829
xmlns:utu="using:Uno.Toolkit.UI"
2930
...
@@ -36,3 +37,16 @@ xmlns:utu="using:Uno.Toolkit.UI"
3637
SubHeaderForeground="Black" />
3738
<TextBlock Text="Asd" />
3839
```
40+
# [**C#**](#tab/csharp)
41+
```cs
42+
new TextBlock()
43+
.Text("Asd"),
44+
new Divider(),
45+
new TextBlock()
46+
.Text("Asd"),
47+
new Divider()
48+
.Foreground(Colors.Gray)
49+
.SubHeader("Separator")
50+
.SubHeaderForeground(Colors.Black)
51+
```
52+
***

doc/controls/DrawerControl.md

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,32 @@ Due to the lack of clipping, this control should be used as a full window-sized
1717
public partial class DrawerControl : ContentControl
1818
```
1919

20-
### XAML
20+
### Usage
21+
# [**XAML**](#tab/xaml)
2122
```xml
2223
xmlns:utu="using:Uno.Toolkit.UI"
2324
...
2425

2526
<utu:DrawerControl>
2627
<utu:DrawerControl.Content>
27-
content
28+
<!-- content -->
2829
</utu:DrawerControl.Content>
2930
<utu:DrawerControl.DrawerContent>
30-
drawerContent
31+
<!-- drawerContent -->
3132
</utu:DrawerControl.DrawerContent>
3233
</utu:DrawerControl>
3334
```
35+
# [**C#**](#tab/csharp)
36+
```cs
37+
new DrawerControl()
38+
.Content(
39+
// content
40+
)
41+
.DrawerContent(
42+
// drawerContent
43+
)
44+
```
45+
***
3446

3547
### Inheritance
3648
Object &#8594; DependencyObject &#8594; UIElement &#8594; FrameworkElement &#8594; Control &#8594; ContentControl &#8594; DrawerControl
@@ -55,6 +67,7 @@ OpenDirection|DrawerOpenDirection=Right|Gets or sets the direction in which the
5567

5668
### Usage
5769
#### Basic usage
70+
# [**XAML**](#tab/xaml)
5871
```xml
5972
xmlns:toolkit="using:Uno.UI.Toolkit"
6073
xmlns:utu="using:Uno.Toolkit.UI"
@@ -68,15 +81,34 @@ xmlns:utu="using:Uno.Toolkit.UI"
6881
<utu:DrawerControl.DrawerContent>
6982
<Grid toolkit:VisibleBoundsPadding.PaddingMask="All"
7083
Padding="16">
71-
<!-- Drawer Content... -->
84+
<!-- Drawer Content ... -->
7285
<TextBlock Text="Drawer" />
7386
</Grid>
7487
</utu:DrawerControl.DrawerContent>
7588
</utu:DrawerControl>
7689
```
77-
90+
# [**C#**](#tab/csharp)
91+
```cs
92+
new DrawerControl()
93+
.Content(
94+
// Main Content ...
95+
new Frame()
96+
)
97+
.DrawerContent(
98+
new Grid()
99+
.VisibleBoundsPadding(PaddingMask.All)
100+
.Padding(16)
101+
.Children(
102+
// DrawerControl ...
103+
new TextBlock()
104+
.Text("Drawer")
105+
)
106+
)
107+
```
108+
***
78109
#### NavigationView with drawer
79110
The `DrawerControl` can also be used to enhance [`NavigationView` (muxc)](https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.controls.navigationview?view=winui-3.0) with gesture support, using the `DrawerNavigationViewStyle`:
111+
# [**XAML**](#tab/xaml)
80112
```xml
81113
xmlns:utu="using:Uno.Toolkit.UI"
82114
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
@@ -97,7 +129,28 @@ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
97129
</muxc:NavigationView.Content>
98130
</muxc:NavigationView>
99131
```
100-
132+
# [**C#**](#tab/csharp)
133+
```cs
134+
new NavigationView()
135+
.PaneTitle("Gesture NavView")
136+
.OpenPaneLength(320)
137+
.DrawerControlBehavior(fitToDrawerContent: false)
138+
//TODO Couldnt find Drawer Style
139+
.Style(Theme.NavigationView.Styles.Drawer)
140+
.MenuItems(
141+
new NavigationViewItem()
142+
.Content("Home"),
143+
new NavigationViewItem()
144+
.Content("Page 1"),
145+
new NavigationViewItem()
146+
.Content("Page 2"),
147+
new NavigationViewItem()
148+
.Content("Page 3")
149+
)
150+
.Content(
151+
new Frame()
152+
)
153+
```
101154
From the `NavigationView`, the properties of the `DrawerControl` can be accessed through the same/similarly named properties or via attached properties:
102155

103156
DrawerControl|NavigationView

doc/controls/DrawerFlyoutPresenter.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ uid: Toolkit.Controls.DrawerFlyoutPresenter
88
## Properties
99
### Remarks
1010
All of the properties below can be used both as a dependency property or as an attached property, much like the `ScrollViewer` properties:
11+
# [**XAML**](#tab/xaml)
1112
```xml
1213
xmlns:utu="using:Uno.Toolkit.UI"
1314

@@ -25,6 +26,22 @@ xmlns:utu="using:Uno.Toolkit.UI"
2526
LightDismissOverlayBackground="#80808080"
2627
IsGestureEnabled="True" />
2728
```
29+
# [**C#**](#tab/csharp)
30+
```cs
31+
new Style<FlyoutPresenter>()
32+
.BasedOn("DrawerFlyoutPresenterStyle")
33+
.Setters(s => s.DrawerFlyoutPresenter(x => x.OpenDirection(DrawerOpenDirection.Up)))
34+
.Setters(s => s.DrawerFlyoutPresenter(x => x.LightDismissOverlayBackground("#80808080")))
35+
.Setters(s => s.DrawerFlyoutPresenter(x => x.IsGestureEnabled(true)))
36+
// and/or
37+
new DrawerFlyoutPresenter()
38+
.OpenDirection(DrawerOpenDirection.Up)
39+
.LightDismissOverlayBackground("#80808080")
40+
.IsGestureEnabled(true)
41+
```
42+
> [!IMPORTANT]
43+
> `DrawerLength` is currently not supported in C# Markup.
44+
***
2845

2946
> [!IMPORTANT]
3047
> There is currently a bug on windows that prevents the usage of attached property style setters. The workaround is to add the following code in your application:
@@ -88,6 +105,7 @@ To use this, simply use a `Flyout` with `Placement="Full"` and one of the follow
88105
- `BottomDrawerFlyoutPresenterStyle` (OpenDirection=Up)
89106

90107
Example:
108+
# [**XAML**](#tab/xaml)
91109
```xml
92110
<Button Content="Bottom Drawer"
93111
xmlns:toolkit="using:Uno.UI.Toolkit">
@@ -103,11 +121,35 @@ Example:
103121
</Button.Flyout>
104122
</Button>
105123
```
124+
# [**C#**](#tab/csharp)
125+
```cs
126+
new Button()
127+
.Flyout(
128+
new Flyout()
129+
.Placement(FlyoutPlacementMode.Full)
130+
//TODO couldn't find BottomDrawer style
131+
.FlyoutPresenterStyle(Theme.FlyoutPresenter.Styles.BottomDrawer)
132+
.Content(
133+
new StackPanel()
134+
.VisibleBoundsPadding(PaddingMask.All)
135+
.Background(Colors.SkyBlue)
136+
.MinHeight(200)
137+
.Children(
138+
new TextBlock()
139+
.Text("text"),
140+
new Button()
141+
.Content("button")
142+
)
143+
)
144+
)
145+
```
146+
***
106147
> [!NOTE]
107148
> Here `VisibleBoundsPadding.PaddingMask` is used to prevent the content from being placed outside of the user-interactable area on mobile devices.
108149
109150
### Extended Use Cases
110151
- Rounded Corner
152+
# [**XAML**](#tab/xaml)
111153
```xml
112154
<Flyout Placement="Full">
113155
<Flyout.FlyoutPresenterStyle>
@@ -120,8 +162,27 @@ Example:
120162
</Border>
121163
</Flyout>
122164
```
165+
# [**C#**](#tab/csharp)
166+
```cs
167+
new Flyout()
168+
.Placement(FlyoutPlacementMode.Full)
169+
.FlyoutPresenterStyle(
170+
new Style<FlyoutPresenter>()
171+
.BasedOn("BottomDrawerFlyoutPresenterStyle")
172+
.Setters(s => s.CornerRadius(new CornerRadius(16, 16, 0, 0)))
173+
)
174+
.Content(
175+
new Border()
176+
.VisibleBoundsPadding(PaddingMask.All)
177+
.Padding(new Thickness(16, 16, 0, 0))
178+
)
179+
```
180+
***
181+
123182
> remarks: `Padding` is used on the flyout content to avoid content being clipped.
183+
124184
- Custom background
185+
# [**XAML**](#tab/xaml)
125186
```xml
126187
<Flyout Placement="Full">
127188
<Flyout.FlyoutPresenterStyle>
@@ -134,8 +195,29 @@ Example:
134195
</Border>
135196
</Flyout>
136197
```
198+
# [**C#**](#tab/csharp)
199+
```cs
200+
new Flyout()
201+
.Placement(FlyoutPlacementMode.Full)
202+
.FlyoutPresenterStyle(
203+
new Style<FlyoutPresenter>()
204+
.BasedOn("BottomDrawerFlyoutPresenterStyle")
205+
.Setters(s => s.Background(Colors.SkyBlue))
206+
)
207+
.Content(
208+
new Border()
209+
.VisibleBoundsPadding(PaddingMask.All)
210+
.Padding(new Thickness(16, 16, 0, 0))
211+
)
212+
```
213+
***
137214
> remarks: Avoid setting `Background` directly on the flyout content:
138215
> ```xml
139216
> <Border toolkit:VisibleBoundsPadding.PaddingMask="All" Background="SkyBlue">
140217
> ```
218+
> ```cs
219+
> new Border()
220+
> .Placement(FlyoutPlacementMode.Full)
221+
> .Background(Colors.SkyBlue)
222+
> ```
141223
> Instead, `Background` should be set from style setter to avoid edge bleeding on certain platforms, and to avoid default background being painted on the rounded corners.

0 commit comments

Comments
 (0)