Skip to content

Commit c4e9072

Browse files
authored
Update getting-started.md
1 parent 7feb472 commit c4e9072

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

docs/docs/getting-started.md

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Getting Started
22

3-
### 1. Create a New WinUI3 or Uno Project
3+
### 1. Create a New WinUI3
44

5-
If you don't already have a WinUI 3 project or Uno prject, create one in Visual Studio.
5+
If you don't already have a WinUI 3 project prject, create one in Visual Studio.
66

77
### 2: Install NuGet Package
88
Inatall `WinUI.TableView` NuGet package to your app with your preferred method. Here is the one using NuGet Package Manager:
@@ -14,66 +14,40 @@ Install-Package WinUI.TableView
1414

1515
In your `MainWindow.xaml`, add the `WinUI.TableView` control:
1616

17-
```xaml
17+
```xml
1818
<Window
1919
x:Class="App1.MainWindow"
2020
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2121
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
22-
xmlns:local="using:App1"
2322
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
2423
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
24+
xmlns:tv="using:WinUI.TableView"
2525
mc:Ignorable="d"
26-
xmlns:tv="using:WinUI.TableView">
26+
Title="App1">
27+
28+
<Window.SystemBackdrop>
29+
<MicaBackdrop />
30+
</Window.SystemBackdrop>
2731

2832
<Grid>
29-
<tv:TableView x:Name="MyTableView"
30-
ItemsSource="{x:Bind ViewModel.Items}" />
33+
<tv:TableView ItemsSource="{x:Bind Items}" />
3134
</Grid>
3235
</Window>
3336
```
3437

3538
### 4. Bind Data to `TableView`
3639

37-
In your `MainPage.xaml.cs`, set up the data context and bind data to the `TableView`:
38-
39-
```csharp
40-
public sealed partial class MainWindow : Window
41-
{
42-
public MainViewModel ViewModel { get; } = new MainViewModel();
43-
44-
public MainWindow()
45-
{
46-
this.InitializeComponent();
47-
}
48-
}
49-
```
50-
51-
Create a simple `MainViewModel` with a collection of items to display:
40+
Create a simple Model class with properties to represent in TableView cells:
5241

5342
```csharp
54-
public class MainViewModel
55-
{
56-
public ObservableCollection<Item> Items { get; set; }
57-
58-
public MainViewModel()
59-
{
60-
Items = new ObservableCollection<Item>
61-
{
62-
new Item { Name = "Item 1", Price = 10.0, Quantity = 1 },
63-
new Item { Name = "Item 2", Price = 15.0, Quantity = 2 },
64-
new Item { Name = "Item 3", Price = 20.0, Quantity = 3 },
65-
// Add more items here
66-
};
67-
}
68-
}
69-
7043
public class Item : INotifyPropertyChanged
7144
{
72-
private string _name;
45+
private string? _name;
7346
private double _price;
7447
private int _quantity;
48+
private DateOnly _purchaseDate;
7549

76-
public string Name
50+
public string? Name
7751
{
7852
get => _name;
7953
set
@@ -100,16 +74,56 @@ public class Item : INotifyPropertyChanged
10074
OnPropertyChanged(nameof(Quantity));
10175
}
10276
}
77+
public DateOnly PurchaseDate
78+
{
79+
get => _purchaseDate;
80+
set
81+
{
82+
_purchaseDate = value;
83+
OnPropertyChanged(nameof(PurchaseDate));
84+
}
85+
}
10386

10487
private void OnPropertyChanged(string propertyName)
10588
{
10689
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
10790
}
10891

109-
public event PropertyChangedEventHandler PropertyChanged;
92+
public event PropertyChangedEventHandler? PropertyChanged;
93+
}
94+
```
95+
96+
In your `MainWindow.xaml.cs`, set up the data context and bind data to the `TableView`:
97+
98+
```csharp
99+
public sealed partial class MainWindow : Window
100+
{
101+
public IList Items { get; }
102+
103+
public MainWindow()
104+
{
105+
this.InitializeComponent();
106+
107+
Items = Enumerable.Range(1, 20).Select(i => GetRandomItem(i)).ToList();
108+
}
109+
110+
private static Item GetRandomItem(int i)
111+
{
112+
return new Item
113+
{
114+
Name = $"Random Item {i}",
115+
Price = Math.Round(Random.Shared.NextDouble() * 100, 2),
116+
Quantity = Random.Shared.Next(1, 100),
117+
PurchaseDate = DateOnly.FromDateTime(DateTime.Today.AddDays(Random.Shared.Next(-90, 90)))
118+
};
119+
}
110120
}
111121
```
112122

113123
### 5. Run Your Application
114124

115-
Build and run your application. You should see the `TableView` populated with the rows and cells from your `ViewModel`.
125+
Build and run your application. You should see the `WinUI.TableView` populated with the rows and cells from your `Items` collection. Here is the result by running the app on Desktop platform.
126+
127+
128+
![image](https://github.com/user-attachments/assets/e00bffc7-19e0-40bd-bbda-07198d6bc60a)
129+

0 commit comments

Comments
 (0)