From c1264d0b62ee0532cf2ef467d528e093723e8e08 Mon Sep 17 00:00:00 2001 From: EzhilarasanElangovan31 Date: Wed, 30 Oct 2024 13:53:50 +0530 Subject: [PATCH 1/2] Updated view model --- .../Chart_GettingStarted/ChartViewModel.cs | 24 ------------ .../Chart_GettingStarted/MainPage.xaml | 12 +++--- .../Chart_GettingStarted/Stage.cs | 14 ------- README.md | 37 ++++++++++--------- 4 files changed, 26 insertions(+), 61 deletions(-) delete mode 100644 Chart_GettingStarted/Chart_GettingStarted/ChartViewModel.cs delete mode 100644 Chart_GettingStarted/Chart_GettingStarted/Stage.cs diff --git a/Chart_GettingStarted/Chart_GettingStarted/ChartViewModel.cs b/Chart_GettingStarted/Chart_GettingStarted/ChartViewModel.cs deleted file mode 100644 index 7a5bb04..0000000 --- a/Chart_GettingStarted/Chart_GettingStarted/ChartViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chart_GettingStarted -{ - public class ChartViewModel - { - public List Data { get; set; } - - public ChartViewModel() - { - Data = new List() - { - new Stage(){Name = "Stage A", Value=12}, - new Stage(){Name = "Stage B", Value=21}, - new Stage(){Name = "Stage C", Value=29}, - new Stage(){Name = "Stage D", Value=37}, - }; - } - } -} diff --git a/Chart_GettingStarted/Chart_GettingStarted/MainPage.xaml b/Chart_GettingStarted/Chart_GettingStarted/MainPage.xaml index 7411659..9171a95 100644 --- a/Chart_GettingStarted/Chart_GettingStarted/MainPage.xaml +++ b/Chart_GettingStarted/Chart_GettingStarted/MainPage.xaml @@ -6,18 +6,18 @@ x:Class="Chart_GettingStarted.MainPage"> - + - + diff --git a/Chart_GettingStarted/Chart_GettingStarted/Stage.cs b/Chart_GettingStarted/Chart_GettingStarted/Stage.cs deleted file mode 100644 index fc7762d..0000000 --- a/Chart_GettingStarted/Chart_GettingStarted/Stage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chart_GettingStarted -{ - public class Stage - { - public string Name { get; set; } - public double Value { get; set; } - } -} diff --git a/README.md b/README.md index 0b1ee9c..d578594 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ public partial class MainWindow : ContentPage { this.InitializeComponent(); SfPyramidChart chart = new SfPyramidChart(); + this.Content = chart; } } ``` @@ -72,38 +73,38 @@ Now, let us define a simple data model that represents a data point in the chart **[C#]** ``` - public class Stage + public class StageModel { public string Name { get; set; } public double Value { get; set; } } ``` -Next, create a view model class and initialize a list of `Model` objects as follows. +Next, create a StageViewModel class and initialize a list of `StageModel` objects as follows. **[C#]** ``` -public class ChartViewModel +public class StageViewModel { - public List Data { get; set; } + public List Data { get; set; } - public ChartViewModel() + public StageViewModel() { - Data = new List() + Data = new List() { - new Stage(){Name = "Stage A", Value = 12}, - new Stage(){Name = "Stage B", Value = 21}, - new Stage(){Name = "Stage C", Value = 29}, - new Stage(){Name = "Stage D", Value = 37}, + new StageModel(){Name = "Stage A", Value = 12}, + new StageModel(){Name = "Stage B", Value = 21}, + new StageModel(){Name = "Stage C", Value = 29}, + new StageModel(){Name = "Stage D", Value = 37}, }; } } ``` -Create a `ViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `ViewModel` class. +Create a `StageViewModel` instance and set it as the chart's `BindingContext`. This enables property binding from `StageViewModel` class. > **_Note:_** -Add the namespace of `ViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML. +Add the namespace of `StageViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML. **[XAML]** ``` @@ -114,7 +115,7 @@ Add the namespace of `ViewModel` class to your XAML Page, if you prefer to set ` - + @@ -122,8 +123,10 @@ Add the namespace of `ViewModel` class to your XAML Page, if you prefer to set ` **[C#]** ``` -ChartViewModel viewModel = new ChartViewModel(); +SfPyramidChart chart = new SfPyramidChart(); +StageViewModel viewModel = new StageViewModel(); chart.BindingContext = viewModel; +this.Content = chart; ``` ## Populate chart with data @@ -142,7 +145,7 @@ chart.BindingContext = viewModel; **[C#]** ``` SfPyramidChart chart = new SfPyramidChart(); -ChartViewModel viewModel = new ChartViewModel(); +StageViewModel viewModel = new StageViewModel(); chart.BindingContext = viewModel; chart.ItemsSource = viewModel.Data; chart.XBindingPath = "Name"; @@ -243,7 +246,7 @@ The following code example gives you the complete code of above configurations.