From d2c77faa7135c972aba5bc0ef5c10248cbc36f10 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Mon, 6 May 2024 17:53:05 +0100 Subject: [PATCH 1/7] docs: Add CSM CallBack usage to Name method --- .../Appendix/AccessingControlInstance.md | 28 +++++++++++++++++-- doc/Learn/Markup/HowTo-CustomMarkupProject.md | 8 +++--- doc/Learn/Markup/SourceUsage.md | 6 ++-- doc/Learn/Markup/Styles.md | 2 +- doc/Learn/Markup/VisualStateManager.md | 4 +-- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/doc/Learn/Markup/Appendix/AccessingControlInstance.md b/doc/Learn/Markup/Appendix/AccessingControlInstance.md index 255351bb97..08c30933ea 100644 --- a/doc/Learn/Markup/Appendix/AccessingControlInstance.md +++ b/doc/Learn/Markup/Appendix/AccessingControlInstance.md @@ -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 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 `Name` method as follows: ```cs this.Content( new StackPanel() .Children( new Button() - .Assign(out var button) + .Name(out var button) .Content("Press Me") ) ); @@ -21,3 +21,27 @@ button.Click += delegate { button.Content = $"Clicked {i++} times"; } ``` + +You can also define a CallBack using the `Name` method: + +```cs +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") + ) +); +``` + + > [!NOTE] + > Using the `.Name(out var c)` 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 `slider`. \ No newline at end of file diff --git a/doc/Learn/Markup/HowTo-CustomMarkupProject.md b/doc/Learn/Markup/HowTo-CustomMarkupProject.md index c24e1d63ec..b817f48a20 100644 --- a/doc/Learn/Markup/HowTo-CustomMarkupProject.md +++ b/doc/Learn/Markup/HowTo-CustomMarkupProject.md @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/doc/Learn/Markup/SourceUsage.md b/doc/Learn/Markup/SourceUsage.md index 76f07b1c41..6030fd94dd 100644 --- a/doc/Learn/Markup/SourceUsage.md +++ b/doc/Learn/Markup/SourceUsage.md @@ -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 @@ -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 @@ -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 diff --git a/doc/Learn/Markup/Styles.md b/doc/Learn/Markup/Styles.md index 37332a089e..18c3e82481 100644 --- a/doc/Learn/Markup/Styles.md +++ b/doc/Learn/Markup/Styles.md @@ -43,7 +43,7 @@ The second way is to provide a `Style` instance. ```cs new Style() - .Assign(out var baseStyle); + .Name(out var baseStyle); new Style() .BasedOn(baseStyle) diff --git a/doc/Learn/Markup/VisualStateManager.md b/doc/Learn/Markup/VisualStateManager.md index 19f5468924..7d88793a4b 100644 --- a/doc/Learn/Markup/VisualStateManager.md +++ b/doc/Learn/Markup/VisualStateManager.md @@ -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 @@ -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 From 327e4cbe40e4942b7ebb3b544d4f86498e350aa6 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Tue, 7 May 2024 11:34:28 +0100 Subject: [PATCH 2/7] chore: Update CSM Name docs with new usage --- .../Appendix/AccessingControlInstance.md | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/doc/Learn/Markup/Appendix/AccessingControlInstance.md b/doc/Learn/Markup/Appendix/AccessingControlInstance.md index 08c30933ea..a165b89629 100644 --- a/doc/Learn/Markup/Appendix/AccessingControlInstance.md +++ b/doc/Learn/Markup/Appendix/AccessingControlInstance.md @@ -4,7 +4,7 @@ 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 `Name` 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 this.Content( @@ -27,6 +27,27 @@ You can also define a CallBack using the `Name` method: ```cs int i = 1; +this.Content( + new StackPanel() + .Children( + new Button() + .Name(button => + { + b.Click += (s, e) => + { + b.Content = $"Clicked {i++} times"; + }; + }) + .Content("Press Me") + ) +); +``` + +Or if you want to expose a variable and also define a CallBack: + +```cs +int i = 1; + this.Content( new StackPanel() .Children( @@ -41,7 +62,9 @@ this.Content( .Content("Press Me") ) ); + +var buttonContent = button.Content; ``` > [!NOTE] - > Using the `.Name(out var c)` 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 `slider`. \ No newline at end of file + > 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`. \ No newline at end of file From 3f5ce511062ce1336deb818cc7cfcb2759779fd6 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Tue, 7 May 2024 11:36:54 +0100 Subject: [PATCH 3/7] chore: Fix minor error --- doc/Learn/Markup/Appendix/AccessingControlInstance.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/Learn/Markup/Appendix/AccessingControlInstance.md b/doc/Learn/Markup/Appendix/AccessingControlInstance.md index a165b89629..733da46dac 100644 --- a/doc/Learn/Markup/Appendix/AccessingControlInstance.md +++ b/doc/Learn/Markup/Appendix/AccessingControlInstance.md @@ -6,7 +6,7 @@ uid: Uno.Extensions.Markup.Appendix.AccessingControlInstance 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( @@ -24,7 +24,7 @@ button.Click += delegate { You can also define a CallBack using the `Name` method: -```cs +```csharp int i = 1; this.Content( @@ -33,9 +33,9 @@ this.Content( new Button() .Name(button => { - b.Click += (s, e) => + button.Click += (s, e) => { - b.Content = $"Clicked {i++} times"; + button.Content = $"Clicked {i++} times"; }; }) .Content("Press Me") @@ -45,7 +45,7 @@ this.Content( Or if you want to expose a variable and also define a CallBack: -```cs +```csharp int i = 1; this.Content( From 67391163466c20bc823880f0aabbd4941d78a7ca Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Wed, 8 May 2024 19:49:56 +0100 Subject: [PATCH 4/7] chore: Add Source and Relative Source to toc --- doc/Learn/Markup/toc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Learn/Markup/toc.yml b/doc/Learn/Markup/toc.yml index 93d2ff9daf..3669dead31 100644 --- a/doc/Learn/Markup/toc.yml +++ b/doc/Learn/Markup/toc.yml @@ -17,6 +17,8 @@ href: xref:Uno.Extensions.Markup.StaticAndThemeResources - name: Using Uno.Themes.WinUI.Markup href: xref:Uno.Extensions.Markup.UnoThemes + - name: Source and Relative Source + href: xref:Uno.Extensions.Markup.SourceUsage - name: Attached Properties href: xref:Uno.Extensions.Markup.AttachedProperties - name: Resource Dictionaries From deec6a3ce8fc911fa81e4cdd986d5e12819305ba Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Thu, 9 May 2024 17:33:38 +0100 Subject: [PATCH 5/7] chore: Remove Source page from toc --- doc/Learn/Markup/toc.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/Learn/Markup/toc.yml b/doc/Learn/Markup/toc.yml index 3669dead31..93d2ff9daf 100644 --- a/doc/Learn/Markup/toc.yml +++ b/doc/Learn/Markup/toc.yml @@ -17,8 +17,6 @@ href: xref:Uno.Extensions.Markup.StaticAndThemeResources - name: Using Uno.Themes.WinUI.Markup href: xref:Uno.Extensions.Markup.UnoThemes - - name: Source and Relative Source - href: xref:Uno.Extensions.Markup.SourceUsage - name: Attached Properties href: xref:Uno.Extensions.Markup.AttachedProperties - name: Resource Dictionaries From 5ff906353404642e17ef452ae01cb164329c554c Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Thu, 16 May 2024 09:15:57 +0100 Subject: [PATCH 6/7] chore: Remove unecessary example --- doc/Learn/Markup/DependencyPropertyBuilder.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/doc/Learn/Markup/DependencyPropertyBuilder.md b/doc/Learn/Markup/DependencyPropertyBuilder.md index 6b174430b2..807d18d5b8 100644 --- a/doc/Learn/Markup/DependencyPropertyBuilder.md +++ b/doc/Learn/Markup/DependencyPropertyBuilder.md @@ -45,7 +45,7 @@ If you wish to perform tasks such as manipulate the value of the binding or form ### Reference Sources -Sometimes you aren't binding to the `DataContext` of the 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: +Sometimes you aren't binding to the `DataContext` of the element and instead, you need to reference another source: ```cs new Slider().Name(out var slider), @@ -58,17 +58,6 @@ new TextBlock() > [!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 -new TextBlock() - .Text(x => x - .Source("slider") - .Binding(() => slider.Value)), -new Slider().Name("slider") -``` - ## Additional Reading - [Binding 101](xref:Uno.Extensions.Markup.Binding101) From 804aa6594c873a6fd07bed990a2fab83f069f2ef Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Fri, 7 Jun 2024 15:33:03 +0100 Subject: [PATCH 7/7] chore: Tweaks after reviews --- doc/Learn/Markup/Appendix/AccessingControlInstance.md | 4 ++-- doc/Learn/Markup/Styles.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/Learn/Markup/Appendix/AccessingControlInstance.md b/doc/Learn/Markup/Appendix/AccessingControlInstance.md index 733da46dac..bacf01c0df 100644 --- a/doc/Learn/Markup/Appendix/AccessingControlInstance.md +++ b/doc/Learn/Markup/Appendix/AccessingControlInstance.md @@ -22,7 +22,7 @@ button.Click += delegate { } ``` -You can also define a CallBack using the `Name` method: +You can also define a `delegate` using the `Name` method: ```csharp int i = 1; @@ -43,7 +43,7 @@ this.Content( ); ``` -Or if you want to expose a variable and also define a CallBack: +Or if you want to expose a variable and also define a `delegate`: ```csharp int i = 1; diff --git a/doc/Learn/Markup/Styles.md b/doc/Learn/Markup/Styles.md index 18c3e82481..37332a089e 100644 --- a/doc/Learn/Markup/Styles.md +++ b/doc/Learn/Markup/Styles.md @@ -43,7 +43,7 @@ The second way is to provide a `Style` instance. ```cs new Style() - .Name(out var baseStyle); + .Assign(out var baseStyle); new Style() .BasedOn(baseStyle)