Skip to content

Commit cf8955d

Browse files
committed
improve DataGrid sample
1 parent 446fc1f commit cf8955d

8 files changed

+209
-107
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=MahAppsMetroDataGridSample_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

MahAppsMetroDataGridSample/MahAppsMetroDataGridSample/MahAppsMetroDataGridSample.csproj

+30
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<DependentUpon>App.xaml</DependentUpon>
6464
<SubType>Code</SubType>
6565
</Compile>
66+
<Compile Include="MainViewModel.cs" />
6667
<Compile Include="MainWindow.xaml.cs">
6768
<DependentUpon>MainWindow.xaml</DependentUpon>
6869
<SubType>Code</SubType>
@@ -104,6 +105,35 @@
104105
<Target Name="AfterBuild">
105106
</Target>
106107
-->
108+
<Choose>
109+
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.5' Or $(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2')">
110+
<ItemGroup>
111+
<Reference Include="JetBrains.Annotations">
112+
<HintPath>..\..\packages\JetBrains.Annotations\lib\net20\JetBrains.Annotations.dll</HintPath>
113+
<Private>True</Private>
114+
<Paket>True</Paket>
115+
</Reference>
116+
</ItemGroup>
117+
</When>
118+
<When Condition="($(TargetFrameworkIdentifier) == '.NETCore') Or ($(TargetFrameworkIdentifier) == 'Silverlight' And $(TargetFrameworkVersion) == 'v4.0') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v7.0' Or $(TargetFrameworkVersion) == 'v7.1')) Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac') Or ($(TargetFrameworkProfile) == 'Profile2') Or ($(TargetFrameworkProfile) == 'Profile3') Or ($(TargetFrameworkProfile) == 'Profile4') Or ($(TargetFrameworkProfile) == 'Profile5') Or ($(TargetFrameworkProfile) == 'Profile6') Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile18') Or ($(TargetFrameworkProfile) == 'Profile23') Or ($(TargetFrameworkProfile) == 'Profile36') Or ($(TargetFrameworkProfile) == 'Profile41') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile46') Or ($(TargetFrameworkProfile) == 'Profile88') Or ($(TargetFrameworkProfile) == 'Profile95') Or ($(TargetFrameworkProfile) == 'Profile96') Or ($(TargetFrameworkProfile) == 'Profile104') Or ($(TargetFrameworkProfile) == 'Profile143') Or ($(TargetFrameworkProfile) == 'Profile154')">
119+
<ItemGroup>
120+
<Reference Include="JetBrains.Annotations.PCL1">
121+
<HintPath>..\..\packages\JetBrains.Annotations\lib\portable-net4+sl4+wp7+netcore45\JetBrains.Annotations.PCL1.dll</HintPath>
122+
<Private>True</Private>
123+
<Paket>True</Paket>
124+
</Reference>
125+
</ItemGroup>
126+
</When>
127+
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == 'Silverlight' And $(TargetFrameworkVersion) == 'v5.0') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch') Or ($(TargetFrameworkProfile) == 'Profile14') Or ($(TargetFrameworkProfile) == 'Profile19') Or ($(TargetFrameworkProfile) == 'Profile24') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile37') Or ($(TargetFrameworkProfile) == 'Profile42') Or ($(TargetFrameworkProfile) == 'Profile47') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile92') Or ($(TargetFrameworkProfile) == 'Profile102') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile136') Or ($(TargetFrameworkProfile) == 'Profile147') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile158') Or ($(TargetFrameworkProfile) == 'Profile225') Or ($(TargetFrameworkProfile) == 'Profile240') Or ($(TargetFrameworkProfile) == 'Profile255') Or ($(TargetFrameworkProfile) == 'Profile259') Or ($(TargetFrameworkProfile) == 'Profile328') Or ($(TargetFrameworkProfile) == 'Profile336') Or ($(TargetFrameworkProfile) == 'Profile344')">
128+
<ItemGroup>
129+
<Reference Include="JetBrains.Annotations.PCL328">
130+
<HintPath>..\..\packages\JetBrains.Annotations\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\JetBrains.Annotations.PCL328.dll</HintPath>
131+
<Private>True</Private>
132+
<Paket>True</Paket>
133+
</Reference>
134+
</ItemGroup>
135+
</When>
136+
</Choose>
107137
<Choose>
108138
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
109139
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Windows;
7+
using System.Windows.Threading;
8+
using JetBrains.Annotations;
9+
using MahAppsMetroDataGridSample.Models;
10+
11+
namespace MahAppsMetroDataGridSample
12+
{
13+
public class MainViewModel : INotifyPropertyChanged
14+
{
15+
public event PropertyChangedEventHandler PropertyChanged;
16+
17+
[NotifyPropertyChangedInvocator]
18+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
19+
{
20+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
21+
}
22+
23+
private DispatcherTimer timer;
24+
private Random random;
25+
26+
public MainViewModel()
27+
{
28+
random = new Random(Int32.MaxValue);
29+
timer = new DispatcherTimer(DispatcherPriority.Background, Application.Current.Dispatcher);
30+
timer.Interval = TimeSpan.FromMilliseconds(100);
31+
timer.Tick += Timer_Tick;
32+
}
33+
34+
private void Timer_Tick(object sender, EventArgs e)
35+
{
36+
if (AlbumCollection.Count >= 5000)
37+
{
38+
Stop();
39+
}
40+
var newAlbum = new Album
41+
{
42+
Title = SampleData.Albums.ElementAt(random.Next(0, SampleData.Albums.Count - 1)).Title,
43+
Genre = SampleData.Genres.ElementAt(random.Next(0, SampleData.Genres.Count - 1)),
44+
Price = (decimal) random.NextDouble()*random.Next(1, 100),
45+
Artist = SampleData.Artists.ElementAt(random.Next(0, SampleData.Artists.Count - 1)),
46+
AlbumArtUrl = "/Content/Images/placeholder.gif"
47+
};
48+
Action action = () => { AlbumCollection.Add(newAlbum); };
49+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(action));
50+
}
51+
52+
public void Start()
53+
{
54+
timer.Start();
55+
}
56+
57+
public void Stop()
58+
{
59+
timer.Stop();
60+
}
61+
62+
public ObservableCollection<Album> AlbumCollection { get; } = new ObservableCollection<Album>();
63+
}
64+
}

0 commit comments

Comments
 (0)