Skip to content

Commit

Permalink
chore: Adjust docs for Source binding
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Mar 6, 2024
1 parent e0c7000 commit e329643
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/Learn/Markup/Binding101.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public partial class MainPage : Page

## Binding to other sources

Sometimes you may want or need to bind to your ViewModel. The first case we'll take a look at is one in which we want to bind to a property of another element. In this case we will use the `Source` method on the `BindingFactory` to update our binding so that it will bind to a named element in the Visual Tree.
Sometimes you may want or need to bind to your ViewModel. The first case we'll take a look at is one in which we want to bind to a property of another element. In this case we will use the `Source` method to update our binding so that it will bind to a named element in the Visual Tree.

```cs
public partial class MainPage : Page
Expand Down
24 changes: 10 additions & 14 deletions doc/Learn/Markup/SourceUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,29 @@ new StackPanel()
.Content("I am a button"),

// Creating a TextBox and binding its Text property to a Button's Content
new TextBox()
.Text(x => x.Source(button)
.Binding(() => button.Content));
)
)
```

```csharp
new StackPanel()
.Children(
new TextBox()
.Assign(out var textbox)
.Assign(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
new Button()
.Content(x => x.Source(textbox)
.Binding(() => textbox.Text)
.Content(x => x.Source(textBox)
.Binding(() => textBox.Text)
.TwoWay());
)
)
```

```csharp
// Binding with a string identifier for the source button
new TextBox()
.Text(x => x.Source<Button>("myButton")
.Binding(b => b.Content));
Expand All @@ -56,12 +53,11 @@ new StackPanel()
.Content("I am a button"),

// Binding to a property of a DataContext
new TextBox()
.Text(x => x.Source(button)
.DataContext<MockViewModel>()
.Binding(v => v.Message));
)
)
```

## Relative Source Binding
Expand All @@ -87,18 +83,18 @@ Example of using RelativeSource to bind a parent property to the element propert
```csharp

var button = new Button()
.Style(
.Style(
new Style<Button>()
.Setters(s => s
.Template(b => new Border()
// Using RelativeSource to bind to a TemplatedParent property in a style template
// Using RelativeSource to bind to a TemplatedParent property in a style template
.Background(x => x.RelativeSource<Button>(RelativeSourceMode.TemplatedParent)
.Binding(x => x.Background)
)
)
)
)
.Background(Colors.Blue);
)
.Background(Colors.Blue);

```

Expand Down

0 comments on commit e329643

Please sign in to comment.