-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e658842
commit 0952ba9
Showing
19 changed files
with
283 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
...Layouts/Layouts/TemplatedComponentBase.cs → ...u.Maui.Layouts/Layouts/TemplateBoxBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Source/Nalu.Maui.Layouts/Layouts/TemplateContentPresenter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Nalu; | ||
|
||
/// <summary> | ||
/// A <see cref="ViewBox"/> to display the <see cref="TemplateBoxBase.TemplateContent" />. | ||
/// </summary> | ||
public class TemplateContentPresenter : ViewBox | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TemplateContentPresenter"/> class. | ||
/// </summary> | ||
public TemplateContentPresenter() | ||
{ | ||
var binding = new Binding(nameof(TemplateBox.TemplateContent), source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(TemplateBoxBase))); | ||
SetBinding(ContentProperty, binding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace Nalu; | ||
|
||
/// <summary> | ||
/// A <see cref="ViewBox"/> that uses a <see cref="DataTemplate"/> to render content based on a boolean value. | ||
/// </summary> | ||
public class ToggleTemplate : TemplateBoxBase | ||
{ | ||
/// <summary> | ||
/// Bindable property for <see cref="WhenTrue"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty WhenTrueProperty = | ||
BindableProperty.Create(nameof(WhenTrue), typeof(DataTemplate), typeof(ToggleTemplate), propertyChanged: ConditionChanged); | ||
|
||
/// <summary> | ||
/// Bindable property for <see cref="WhenFalse"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty WhenFalseProperty = | ||
BindableProperty.Create(nameof(WhenFalse), typeof(DataTemplate), typeof(ToggleTemplate), propertyChanged: ConditionChanged); | ||
|
||
/// <summary> | ||
/// Bindable property for <see cref="Value"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(bool?), typeof(ToggleTemplate), propertyChanged: ConditionChanged); | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="DataTemplate"/> to use when the value is false. | ||
/// </summary> | ||
public DataTemplate? WhenFalse | ||
{ | ||
get => (DataTemplate?)GetValue(WhenFalseProperty); | ||
set => SetValue(WhenFalseProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="DataTemplate"/> to use when the value is true. | ||
/// </summary> | ||
public DataTemplate? WhenTrue | ||
{ | ||
get => (DataTemplate?)GetValue(WhenTrueProperty); | ||
set => SetValue(WhenTrueProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the value to determine which template to use. | ||
/// </summary> | ||
public bool? Value | ||
{ | ||
get => (bool?)GetValue(ValueProperty); | ||
set => SetValue(ValueProperty, value); | ||
} | ||
|
||
private void SetTemplateFromValue() | ||
{ | ||
var template = Value switch | ||
{ | ||
true => WhenTrue, | ||
false => WhenFalse, | ||
_ => null, | ||
}; | ||
|
||
SetTemplate(template); | ||
} | ||
|
||
private static void ConditionChanged(BindableObject bindable, object oldvalue, object newvalue) | ||
{ | ||
if (bindable is ToggleTemplate toggleTemplate) | ||
{ | ||
toggleTemplate.SetTemplateFromValue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.