-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
fb792bf
commit c82e7f8
Showing
11 changed files
with
372 additions
and
200 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 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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<HorizontalStackLayout xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="MauiConditionView.NumericUpDown"> | ||
<Button Text="-" | ||
Clicked="DecrementClicked" | ||
Margin="0,0,5,0" | ||
HeightRequest="40" | ||
WidthRequest="40" /> | ||
|
||
<Label x:Name="ValueControl" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center"/> | ||
|
||
<Button Text="+" | ||
Clicked="IncrementClicked" | ||
Margin="5,0,0,0" | ||
HeightRequest="40" | ||
WidthRequest="40" /> | ||
</HorizontalStackLayout> |
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,59 @@ | ||
namespace MauiConditionView; | ||
|
||
using System.Globalization; | ||
|
||
public partial class NumericUpDown | ||
{ | ||
public NumericUpDown() | ||
{ | ||
InitializeComponent(); | ||
ValueControl.Text = Value.ToString(CultureInfo.CurrentCulture); | ||
} | ||
|
||
public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(double), typeof(NumericUpDown), 0.0, BindingMode.TwoWay); | ||
public static readonly BindableProperty MinimumProperty = BindableProperty.Create(nameof(Minimum), typeof(double), typeof(NumericUpDown), 0.0); | ||
public static readonly BindableProperty MaximumProperty = BindableProperty.Create(nameof(Maximum), typeof(double), typeof(NumericUpDown), 100.0); | ||
public static readonly BindableProperty IncrementProperty = BindableProperty.Create(nameof(Increment), typeof(double), typeof(NumericUpDown), 1.0); | ||
|
||
public double Value | ||
{ | ||
get => (double)GetValue(ValueProperty); | ||
set | ||
{ | ||
var newValue = Math.Clamp(value, Minimum, Maximum); | ||
if (!newValue.Equals((double)GetValue(ValueProperty))) | ||
{ | ||
SetValue(ValueProperty, newValue); | ||
ValueControl.Text = newValue.ToString(CultureInfo.CurrentCulture); | ||
} | ||
} | ||
} | ||
|
||
public double Minimum | ||
{ | ||
get => (double)GetValue(MinimumProperty); | ||
set => SetValue(MinimumProperty, value); | ||
} | ||
|
||
public double Maximum | ||
{ | ||
get => (double)GetValue(MaximumProperty); | ||
set => SetValue(MaximumProperty, value); | ||
} | ||
|
||
public double Increment | ||
{ | ||
get => (double)GetValue(IncrementProperty); | ||
set => SetValue(IncrementProperty, value); | ||
} | ||
|
||
private void IncrementClicked(object sender, EventArgs e) | ||
{ | ||
Value += Increment; | ||
} | ||
|
||
private void DecrementClicked(object sender, EventArgs e) | ||
{ | ||
Value -= Increment; | ||
} | ||
} |
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,7 @@ | ||
# .NET MAUI ConditionView | ||
|
||
[![Buy Me A Coffee](https://ik.imagekit.io/VladislavAntonyuk/vladislavantonyuk/misc/bmc-button.png)](https://www.buymeacoffee.com/vlad.antonyuk) | ||
|
||
Article: https://vladislavantonyuk.github.io/articles/Building-Dynamic-UI-with-Decision-Logic-in-.NET-MAUI-XAML | ||
|
||
[![Stand With Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua) |
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,7 @@ | ||
# .NET MAUI ConditionView | ||
|
||
!INCLUDE "./md/header.mdpp" | ||
|
||
Article: https://vladislavantonyuk.github.io/articles/Building-Dynamic-UI-with-Decision-Logic-in-.NET-MAUI-XAML | ||
|
||
!INCLUDE "./md/footer.mdpp" |
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,46 @@ | ||
namespace MauiConditionView; | ||
|
||
public class SwitchCaseView<T> : ContentView | ||
where T : notnull | ||
{ | ||
public static readonly BindableProperty ConditionsProperty = BindableProperty.Create(nameof(Conditions), typeof(ICollection<CaseView<T>>), typeof(ConditionView), new List<CaseView<T>>(), propertyChanged:SwitchChanged); | ||
public static readonly BindableProperty DefaultProperty = BindableProperty.Create(nameof(Default), typeof(View), typeof(ConditionView), propertyChanged: SwitchChanged); | ||
public static readonly BindableProperty SwitchProperty = BindableProperty.Create(nameof(Switch), typeof(T), typeof(ConditionView), propertyChanged: SwitchChanged); | ||
|
||
private static void SwitchChanged(BindableObject bindable, object oldvalue, object newvalue) | ||
{ | ||
var switchCaseView = (SwitchCaseView<T>)bindable; | ||
switchCaseView.Content = switchCaseView.Conditions | ||
.Where(x => x.Case.Equals(switchCaseView.Switch)) | ||
.Select(x => x.Content) | ||
.SingleOrDefault(switchCaseView.Default); | ||
} | ||
|
||
public T Switch | ||
{ | ||
get => (T)GetValue(SwitchProperty); | ||
set => SetValue(SwitchProperty, value); | ||
} | ||
|
||
public View? Default | ||
{ | ||
get => (View?)GetValue(DefaultProperty); | ||
set => SetValue(DefaultProperty, value); | ||
} | ||
|
||
public ICollection<CaseView<T>> Conditions | ||
{ | ||
get => (ICollection<CaseView<T>>)GetValue(ConditionsProperty); | ||
set => SetValue(ConditionsProperty, value); | ||
} | ||
} | ||
|
||
public class CaseView<T> : ContentView | ||
{ | ||
public static readonly BindableProperty CaseProperty = BindableProperty.Create(nameof(Case), typeof(T), typeof(CaseView<T>)); | ||
public T Case | ||
{ | ||
get => (T)GetValue(CaseProperty); | ||
set => SetValue(CaseProperty, value); | ||
} | ||
} |
Oops, something went wrong.