Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Change Assign usage for Name #2194

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions doc/Learn/Markup/Binding101.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ public partial class MainPage : Page
this.DataContext<MyViewModel>((page, vm) => page
.Content(
new TextBox()
.Assign(out var searchBox)
.Text(() => vm.Query)
.Name("SearchBox"),
.Name(out var searchBox)
.Text(() => vm.Query),
new TextBox()
.Text(x => x
.Source("SearchBox")
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
.Source(searchBox)
.Binding(() => searchBox.Text))
)
);
Expand Down
6 changes: 5 additions & 1 deletion doc/Learn/Markup/DependencyPropertyBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ If you wish to perform tasks such as manipulate the value of the binding or form
Sometimes you aren't binding to the `DataContext` of element and instead you need to reference another source. With WinUI we have 2 ways of doing this. The first is that we could specify a source directly such as:
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved

```cs
new Slider().Assign(out var slider),
new Slider().Name(out var slider),
new TextBlock()
.Text(x => x
.Source(slider)
.Binding(() => slider.Value))
```

> [!NOTE]
> Using the `.Name(out var fe)` syntax not only gives you a variable representing your `FrameworkElement` control but also sets the control's `Name` property to match the variable name. For example, in the scenario mentioned earlier, the `Slider` would have its `Name` property set to "slider" because the variable name used is `slider`.


The second is that we can leverage the element name for our binding such as the following:

```cs
Expand Down
2 changes: 1 addition & 1 deletion doc/Learn/Markup/HowTo-CustomMarkupProject-Theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ new Grid().RowDefinitions<Grid>("*, *")
.Grid(column: 0)
.Content("Toggle Theme")
.HorizontalAlignment(HorizontalAlignment.Right)
.Assign(out var toggle)
.Name(out var toggle)
),
```

Expand Down
28 changes: 14 additions & 14 deletions doc/Learn/Markup/HowTo-CustomMarkupProject-Toolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The navigation bar can include items such as a back button, a page title, and ot
new NavigationBar().Content("Title Second Page"),
new Button()
.Content("Go to Main Page")
.Assign(out var navigationButton)
.Name(out var navigationButton)
));

navigationButton.Click += (s, e) =>
Expand All @@ -72,10 +72,10 @@ The navigation bar can include items such as a back button, a page title, and ot
```csharp
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
```

The main ideia here is to create a button that have Assign it self the output variable named in this case as navigationButton.
The main ideia here is to create a button that have assign itself, through the `Name` extension method, the output variable named in this case as `navigationButton`.
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
After that we need to add a Click EventHandler to add the Navigation using the Frame.Navigate.
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved

> Notice how simple it is to create an action for the Button's Click event.
Expand Down Expand Up @@ -168,7 +168,7 @@ The navigation bar can include items such as a back button, a page title, and ot
new NavigationBar().Content("Title Main Page"),
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton)
.Name(out var navigationButton)
));

navigationButton.Click += (s, e) =>
Expand Down Expand Up @@ -242,13 +242,13 @@ Chips are often used to display short pieces of information such as tags, catego

```csharp
new ChipGroup()
.Assign(out var chipGroup)
.Name(out var chipGroup)
.Items(
new Chip()
.Margin(5)
.Content("Go to Second Page")
.Background(new SolidColorBrush(Colors.LightBlue))
.Assign(out var navigationChip),
.Name(out var navigationChip),
)
```

Expand All @@ -259,7 +259,7 @@ Chips are often used to display short pieces of information such as tags, catego

```csharp
new ChipGroup()
.Assign(out var chipGroup)
.Name(out var chipGroup)
.Items(
new Chip()
.Margin(5)
Expand All @@ -274,18 +274,18 @@ Chips are often used to display short pieces of information such as tags, catego

```csharp
new ChipGroup()
.Assign(out var chipGroup)
.Name(out var chipGroup)
.Items(

new Chip()
.Margin(5)
.Content("Chip 3")
.Assign(out var chipElement)
.Name(out var chipElement)
)
```

And we need to add the event handlers on our code.
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
Notice that we are using the Assign to have access to the chipElement in other places.
Notice that we are using the `Name` extension method to have access to the chipElement in other places.

```csharp

Expand Down Expand Up @@ -392,9 +392,9 @@ Chips are often used to display short pieces of information such as tags, catego
.Children(
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
new ChipGroup()
.Assign(out var chipGroup)
.Name(out var chipGroup)
.Items(
new Chip()
.Margin(5)
Expand All @@ -404,7 +404,7 @@ Chips are often used to display short pieces of information such as tags, catego
.Margin(5)
.CanRemove(true)
.Content("Chip 2")
.Assign(out var chipRemoveElement)
.Name(out var chipRemoveElement)
.Style(new Style<Chip>()
.Setters(s => s.Foreground(new SolidColorBrush(Colors.Red)))
),
Expand All @@ -413,7 +413,7 @@ Chips are often used to display short pieces of information such as tags, catego
.Content("Chip 3")
//.Icon(new PathIcon().Data(StaticResource.Get<Geometry>("Icon_Check")))
//.Icon(new SymbolIcon(Symbol.Favorite))
.Assign(out var chipElement)
.Name(out var chipElement)
)
)
)
Expand Down
22 changes: 11 additions & 11 deletions doc/Learn/Markup/HowTo-CustomMarkupProject-VisualStates.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ It provides a way to create custom components that can be used in multiple parts
this.Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
.Content(
new ChipGroup()
.Assign(out var chipGroup)
.Name(out var chipGroup)
.Items(
new Chip()
.Margin(5)
.Content("First Chip")
.Background(new SolidColorBrush(Colors.LightBlue))
.Assign(out var navigationChip),
.Name(out var navigationChip),
new Chip()
.Margin(5)
.Content("Chip 2")
Expand All @@ -49,7 +49,7 @@ It provides a way to create custom components that can be used in multiple parts
new Chip()
.Margin(5)
.Content("Chip 3")
.Assign(out var chipElement)
.Name(out var chipElement)
)
);
```
Expand Down Expand Up @@ -80,7 +80,7 @@ It provides a way to create custom components that can be used in multiple parts
.Children(
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
new SampleUserControl()
)
```
Expand Down Expand Up @@ -109,7 +109,7 @@ It provides a way to create custom components that can be used in multiple parts
.Children(
new Button()
.Content("Go to Main Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
new SampleUserControl()
)
)
Expand Down Expand Up @@ -245,7 +245,7 @@ It provides a way to create custom components that can be used in multiple parts
.Children(
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
new SampleUserControl()
)
)
Expand Down Expand Up @@ -345,7 +345,7 @@ With this we can control events and changes.
)
```

We will change the navigationButton (the same that has been Assign for control the Navigation) and will the Background Color now.
We will change the navigationButton (the same that has been assigned for controlling the navigation) and change its background color now.
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
And change the value of the Width of the Button that will be used on the EventHandler.
You can add the Button before the `new SampleUserControl()`.

Expand All @@ -354,7 +354,7 @@ With this we can control events and changes.
.Width(200)
.Height(40)
.Content("VisualStateManager Test")
.Assign(out var btn),
.Name(out var btn),
```

And to handle the Event Handlers we need to create the Event Handlers so that the events are fired and the actions happen.
Expand Down Expand Up @@ -408,7 +408,7 @@ With this we can control events and changes.
new Button()
.Grid(row: 1)
.Content("Visual State on UserControl")
.Assign(out var visualStateButtonChips)
.Name(out var visualStateButtonChips)
```

And to handle the Event Handlers we need to create the Event Handlers so that the events are fired and the actions happen.
Expand Down Expand Up @@ -581,12 +581,12 @@ With this we can control events and changes.
.Children(
new Button()
.Content("Go to Second Page")
.Assign(out var navigationButton),
.Name(out var navigationButton),
new Button()
.Width(200)
.Height(40)
.Content("VisualStateManager Test")
.Assign(out var btn),
.Name(out var btn),
new SampleUserControl()
)
)
Expand Down
Loading