Skip to content

Commit 1f197d2

Browse files
committed
toast example
1 parent 48da9a0 commit 1f197d2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Samples/Samples.UI.XamarinForms/ToastsPage.xaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
x:Class="Samples.ToastsPage"
@@ -8,14 +8,15 @@
88
<TableRoot>
99
<TableSection Title="Message">
1010
<EntryCell Label="Value" Text="{Binding Message}" />
11-
<EntryCell Label="Text Color" Text="{Binding MessageTextColor}" />
11+
<!-- <EntryCell Label="Text Color" Text="{Binding MessageTextColor}" />-->
1212
</TableSection>
1313
<TableSection Title="Action Color">
1414
<EntryCell Label="Value" Text="{Binding ActionText}" />
15-
<EntryCell Label="Text Color" Text="{Binding ActionTextColor}" />
15+
<!-- <EntryCell Label="Text Color" Text="{Binding ActionTextColor}" />-->
1616
</TableSection>
1717
<TableSection>
18-
<EntryCell Label="Background Color" Text="{Binding BackgroundColor}" />
18+
<SwitchCell Text="Show on Top" On="{Binding ShowOnTop}" />
19+
<!-- <EntryCell Label="Background Color" Text="{Binding BackgroundColor}" />-->
1920
<EntryCell Label="Duration (sec)" Text="{Binding SecondsDuration}" Keyboard="Numeric" />
2021
<TextCell Text="Open Toast" Command="{Binding Open}" />
2122
</TableSection>

src/Samples/Samples/ViewModels/ToastsViewModel.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ToastsViewModel(IUserDialogs dialogs) : base(dialogs)
2020
this.MessageTextColor = ToHex(Color.White);
2121
this.BackgroundColor = ToHex(Color.Blue);
2222

23-
this.Open = new Command(async () =>
23+
this.Open = new Command(() =>
2424
{
2525
// var icon = await BitmapLoader.Current.LoadFromResource("emoji_cool_small.png", null, null);
2626

@@ -35,11 +35,12 @@ public ToastsViewModel(IUserDialogs dialogs) : base(dialogs)
3535
//.SetBackgroundColor(bgColor)
3636
//.SetMessageTextColor(msgColor)
3737
.SetDuration(TimeSpan.FromSeconds(this.SecondsDuration))
38+
.SetPosition(this.ShowOnTop ? ToastPosition.Top : ToastPosition.Bottom)
3839
//.SetIcon(icon)
3940
.SetAction(x => x
4041
.SetText(this.ActionText)
4142
//.SetTextColor(actionColor)
42-
.SetAction(() => dialogs.Alert("You clicked the primary button"))
43+
.SetAction(() => dialogs.Alert("You clicked the primary toast button"))
4344
)
4445
);
4546
});
@@ -98,6 +99,21 @@ public int SecondsDuration
9899
}
99100

100101

102+
bool showOnTop;
103+
public bool ShowOnTop
104+
{
105+
get => this.showOnTop;
106+
set
107+
{
108+
if (this.showOnTop == value)
109+
return;
110+
111+
this.showOnTop = true;
112+
this.OnPropertyChanged();
113+
}
114+
}
115+
116+
101117
string actionText;
102118
public string ActionText
103119
{

0 commit comments

Comments
 (0)