Skip to content

Commit 42a6579

Browse files
Merge pull request #26 from TheEightBot/feature/picker-clear
2 parents c0a86ec + d8c1603 commit 42a6579

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Stellar.Maui/Extensions/PickerExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ private void SetSelectedItem(bool fromNotificationTrigger = false)
416416
}
417417
}
418418

419+
var picker = _picker;
420+
picker?.Dispatcher?.Dispatch(() => picker.ResetToInitialValue());
421+
419422
if (fromNotificationTrigger)
420423
{
421424
SelectedItemChanged(default(TViewModel));

Stellar.MauiSample/UserInterface/Pages/SamplePopupPage.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class SamplePopupPage : PopupPageBase<SampleViewModel>
1313

1414
private BoxView _color;
1515

16+
private Button _clear;
17+
1618
private Picker _picker;
1719

1820
private ListView _listView;
@@ -53,6 +55,12 @@ public override void SetupUserInterface()
5355
VerticalOptions = LayoutOptions.Start,
5456
}
5557
.Assign(out _picker),
58+
new Button
59+
{
60+
Text = "Clear",
61+
VerticalOptions = LayoutOptions.Start,
62+
}
63+
.Assign(out _clear),
5664

5765
new ListView
5866
{
@@ -80,12 +88,16 @@ public override void Bind(WeakCompositeDisposable disposables)
8088
.BindTo(this, static ui => ui._color.BackgroundColor)
8189
.DisposeWith(disposables);
8290

91+
this.BindCommand(ViewModel, vm => vm.Clear, ui => ui._clear, Observables.UnitDefault)
92+
.DisposeWith(disposables);
93+
8394
_picker
8495
.BindPicker(
8596
this.WhenAnyValue(static x => x.ViewModel.TestItems),
8697
x => this.ViewModel.SelectedTestItem = x,
8798
x => this.ViewModel.SelectedTestItem == x,
88-
x => x.Value1)
99+
x => x.Value1,
100+
this.WhenAnyValue(x => x.ViewModel.SelectedTestItem))
89101
.DisposeWith(disposables);
90102

91103
this.OneWayBind(ViewModel, static vm => vm.TestItems, static ui => ui._listView.ItemsSource)

Stellar.MauiSample/ViewModels/SampleViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public partial class SampleViewModel(TestService testService)
2525
[Reactive]
2626
private ReactiveCommand<Unit, Unit> _goNext;
2727

28+
[Reactive]
29+
private ReactiveCommand<Unit, Unit> _clear;
30+
2831
[Reactive]
2932
private byte[] _colorArray;
3033

@@ -92,6 +95,14 @@ protected override void Bind(WeakCompositeDisposable disposables)
9295
ReactiveCommand
9396
.Create(DefaultAction)
9497
.DisposeWith(disposables);
98+
99+
Clear =
100+
ReactiveCommand
101+
.Create(() =>
102+
{
103+
SelectedTestItem = null;
104+
})
105+
.DisposeWith(disposables);
95106
}
96107

97108
public void OnLifecycleEvent(LifecycleEvent lifecycleEvent)

0 commit comments

Comments
 (0)