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: Add CSM CallBack usage to Name method #2279

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
53 changes: 50 additions & 3 deletions doc/Learn/Markup/Appendix/AccessingControlInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ uid: Uno.Extensions.Markup.Appendix.AccessingControlInstance

# Accessing a Control Instance

There are a number of times where you may find yourself wanting to access the instance of a control that you initialized. This could be useful for bindings or even to later configure Event Handlers on the control. You can most easily do this with the `Assign` method as follows:
There are a number of times when you may find yourself wanting to access the instance of a control that you initialized. This could be useful for bindings or even to later configure Event Handlers on the control. You can most easily do this with the `Name` method as follows:

```cs
```csharp
this.Content(
new StackPanel()
.Children(
new Button()
.Assign(out var button)
.Name(out var button)
.Content("Press Me")
)
);
Expand All @@ -21,3 +21,50 @@ button.Click += delegate {
button.Content = $"Clicked {i++} times";
}
```

You can also define a CallBack using the `Name` method:
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved

```csharp
int i = 1;

this.Content(
new StackPanel()
.Children(
new Button()
.Name(button =>
{
button.Click += (s, e) =>
{
button.Content = $"Clicked {i++} times";
};
})
.Content("Press Me")
)
);
```

Or if you want to expose a variable and also define a CallBack:

```csharp
int i = 1;

this.Content(
new StackPanel()
.Children(
new Button()
.Name(out var button, (b) =>
{
b.Click += (s, e) =>
{
b.Content = $"Clicked {i++} times";
};
})
.Content("Press Me")
)
);

var buttonContent = button.Content;
```

> [!NOTE]
> Using the `.Name(out var button)` or `.Name(button => { ... })` 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 `Button` would have its `Name` property set to "button" because the variable name used is `button`.
8 changes: 4 additions & 4 deletions doc/Learn/Markup/HowTo-CustomMarkupProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ In the ViewModel, the Model's data is already loaded into the Instance of the cl
.Text(Title)
.FontSize(18)
.FontWeight(FontWeights.Bold)
.Assign(out var searchText),
.Name(out var searchText),
new TextBlock()
.Text(SubTitle)
.FontSize(16)
Expand Down Expand Up @@ -1335,7 +1335,7 @@ In the ViewModel, the Model's data is already loaded into the Instance of the cl
.Text(Title)
.FontSize(18)
.FontWeight(FontWeights.Bold)
.Assign(out var searchText),
.Name(out var searchText),
new TextBlock()
.Text(SubTitle)
.FontSize(16)
Expand Down Expand Up @@ -1607,7 +1607,7 @@ In the ViewModel, the Model's data is already loaded into the Instance of the cl
.Text(Title)
.FontSize(18)
.FontWeight(FontWeights.Bold)
.Assign(out var searchText),
.Name(out var searchText),
new TextBlock()
.Text(SubTitle)
.FontSize(16)
Expand Down Expand Up @@ -1986,7 +1986,7 @@ In the ViewModel, the Model's data is already loaded into the Instance of the cl
.Text(Title)
.FontSize(18)
.FontWeight(FontWeights.Bold)
.Assign(out var searchText),
.Name(out var searchText),
new TextBlock()
.Text(SubTitle)
.FontSize(16)
Expand Down
6 changes: 3 additions & 3 deletions doc/Learn/Markup/SourceUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Binding a property directly from one UI element to another is a common scenario.
new StackPanel()
.Children(
new Button()
.Assign(out var button)
.Name(out var button)
.Content("I am a button"),

// Creating a TextBox and binding its Text property to a Button's Content
Expand All @@ -27,7 +27,7 @@ new StackPanel()
new StackPanel()
.Children(
new TextBox()
.Assign(out var textBox)
.Name(out var textBox)
.Text("I am a TextBox"),

// Creating a Button and binding its Content property to the TextBox's Text property with TwoWay binding
Expand All @@ -49,7 +49,7 @@ new TextBox()
new StackPanel()
.Children(
new Button()
.Assign(out var button)
.Name(out var button)
.Content("I am a button"),

// Binding to a property of a DataContext
Expand Down
2 changes: 1 addition & 1 deletion doc/Learn/Markup/Styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The second way is to provide a `Style` instance.

```cs
new Style<TextBlock>()
.Assign(out var baseStyle);
.Name(out var baseStyle);
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved

new Style<TextBlock>()
.BasedOn(baseStyle)
Expand Down
4 changes: 2 additions & 2 deletions doc/Learn/Markup/VisualStateManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ When updating the children of a given control, it is important to ensure that th
```cs
new Grid()
.Children(
new TextBlock().Assign(out var textBlock)
new TextBlock().Name(out var textBlock)
)
.VisualStateManager(vsm => vsm
.Group(group => group
Expand All @@ -36,7 +36,7 @@ In addition to adding various style setters to a given state, it is also possibl
```cs
new Grid()
.Children(
new TextBlock().Assign(out var textBlock)
new TextBlock().Name(out var textBlock)
)
.VisualStateManager(vsm => vsm
.Group(group => group
Expand Down
Loading