Skip to content

Commit b600bb3

Browse files
Merge pull request #1 from DiwakarVenkatesan/master
Added sample and updated Readme file
2 parents 6a0fe88 + 4c16792 commit b600bb3

38 files changed

+1182
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
11
# refresh-command-binding-using-mvvm-in-.net-maui-pull-to-refresh
22
This example demonstrates about how to bind the RefreshCommand using MVVM in .NET MAUI PullToRefresh (SfPullToRefresh).
3+
4+
# How to refresh the .NET MAUI PullToRefresh from ViewModel?
5+
6+
`SfPullToRefresh` is fully MVVM compatible and can be refreshed by binding a property in the view model to the [SfPullToRefresh.IsRefreshing]() property.
7+
`SfPullToRefresh` also provides support for [SfPullToRefresh.RefreshCommand]() that will be executed when the pulling is completed and the pointer is released. You can also pass a desired object as parameter to the `SfPullToRefresh.RefreshCommand` using the [SfPullToRefresh.RefreshCommandParameter]().
8+
The `SfPullToRefresh.RefreshCommand's` `CanExecute()` will be fired when the pulling action is performed. Returning `false` in the command's `CanExecute()` will cancel the pulling and the `SfPullToRefresh.RefreshCommand` will not be executed.
9+
10+
{% tabs %}
11+
{% highlight xaml tabtittle="MainPage.xaml" hl_lines="2" %}
12+
13+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
14+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
15+
x:Class="RefreshCommand.MainPage"
16+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PullToRefresh;assembly=Syncfusion.Maui.PullToRefresh"
17+
xmlns:local="clr-namespace:RefreshCommand">
18+
19+
<ContentPage.BindingContext>
20+
<local:ViewModel />
21+
</ContentPage.BindingContext>
22+
23+
<ContentPage.Content>
24+
<syncfusion:SfPullToRefresh x:Name="pullToRefresh"
25+
IsRefreshing="{Binding IsRefreshing}"
26+
PullingThreshold="100"
27+
RefreshCommand="{Binding RefreshCommand}">
28+
<syncfusion:SfPullToRefresh.PullableContent>
29+
<StackLayout BackgroundColor="#00AFF9"
30+
Orientation="Vertical">
31+
<Label Text="New York Temperature"
32+
FontSize="Large"
33+
TextColor="White"
34+
HorizontalTextAlignment="Center"
35+
Margin="20" />
36+
<Label Text="{Binding Temperature}"
37+
FontSize="Large"
38+
TextColor="White"
39+
HorizontalTextAlignment="Center"
40+
Margin="20"
41+
HeightRequest="100" />
42+
</StackLayout>
43+
</syncfusion:SfPullToRefresh.PullableContent>
44+
</syncfusion:SfPullToRefresh>
45+
</ContentPage.Content>
46+
</ContentPage>
47+
48+
{% endhighlight %}
49+
{% highlight c# tabtittle="ViewModel.cs" hl_lines="1" %}
50+
51+
public class ViewModel : INotifyPropertyChanged
52+
{
53+
private bool isRefreshing;
54+
public ICommand RefreshCommand { get; set; }
55+
56+
public bool IsRefreshing
57+
{
58+
get
59+
{
60+
return isRefreshing;
61+
}
62+
set
63+
{
64+
isRefreshing = value;
65+
RaisePropertyChanged(nameof(IsRefreshing));
66+
}
67+
}
68+
69+
public ViewModel()
70+
{
71+
RefreshCommand = new Command(Refresh);
72+
}
73+
74+
async private void Refresh(object obj)
75+
{
76+
IsRefreshing = true;
77+
await Task.Delay(1000);
78+
IsRefreshing = false;
79+
int index = random.Next(0, 6);
80+
Temperature = temperatureArray[index];
81+
}
82+
}
83+
84+
{% endhighlight %}
85+
{% endtabs %}

RefreshCommand/RefreshCommand.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34316.72
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefreshCommand", "RefreshCommand\RefreshCommand.csproj", "{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{B2E32D9F-5F80-492E-B441-B8308B3D0ADA}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {1F91F374-BF41-45A1-8C69-C4676ED7E2B5}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:RefreshCommand"
5+
x:Class="RefreshCommand.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace RefreshCommand
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new MainPage();
10+
}
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="RefreshCommand.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:RefreshCommand"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="RefreshCommand">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace RefreshCommand
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="RefreshCommand.MainPage"
5+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PullToRefresh;assembly=Syncfusion.Maui.PullToRefresh"
6+
xmlns:local="clr-namespace:RefreshCommand">
7+
8+
<ContentPage.BindingContext>
9+
<local:ViewModel />
10+
</ContentPage.BindingContext>
11+
12+
<ContentPage.Content>
13+
<syncfusion:SfPullToRefresh x:Name="pullToRefresh"
14+
IsRefreshing="{Binding IsRefreshing}"
15+
PullingThreshold="100"
16+
RefreshCommand="{Binding RefreshCommand}">
17+
<syncfusion:SfPullToRefresh.PullableContent>
18+
<StackLayout BackgroundColor="#00AFF9"
19+
Orientation="Vertical">
20+
<Label Text="New York Temperature"
21+
FontSize="Large"
22+
TextColor="White"
23+
HorizontalTextAlignment="Center"
24+
Margin="20" />
25+
<Label Text="{Binding Temperature}"
26+
FontSize="Large"
27+
TextColor="White"
28+
HorizontalTextAlignment="Center"
29+
Margin="20"
30+
HeightRequest="100" />
31+
</StackLayout>
32+
</syncfusion:SfPullToRefresh.PullableContent>
33+
</syncfusion:SfPullToRefresh>
34+
</ContentPage.Content>
35+
</ContentPage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace RefreshCommand
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
public MainPage()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace RefreshCommand
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

0 commit comments

Comments
 (0)