Let’s start :)
create new Xamarin.Forms application in Visual Studio for Mac
Once Project created, install “Xamarin.Forms.DataGrid” dependency by going, the Solution Explorer >> right-click and select “Manage NuGet Packages” >> in the new dialog, top right corner search “Xamarin.Forms.DataGrid” and Install it.
Nuget Package Install |
Now, create another DummyProfessionalData.cs class under the Utils folder for dummy data. This class used for creating dummy data and code is given here.
Next, Create MainPageViewModel.cs class under ViewModel folder and write given below code. Here, List and IsRefreshing properties and refresh commend are written, and when the user swipe top to bottom, the refresh command will execute and refresh the UI with updated data. INotifyPropertyChanged property also implemented to invoke the UI with new Data. The Professional Property for single data selection.
After that open MainPage.xaml page and start our UI design. First, we call DataGrid namespace as dg and design our columns with Title, bind the PropertyName, width size. Bind ItemSource, SelectedItem, refershCommand. This page design code is given below.
Next open MainPage.xaml.cs and set BindingContext is MainPageViewModel as we done already. The source code here.
Finally, initialize DataComponent in App Startup of App.xaml.cs class as below code.
Now, run your application and output like the below screenshot.
1 Comments
Hello. Is there a way to implement Context menus using DataGrid? Thank you.
ReplyDeleteYou're comment here