Skip to content

Commit a921ca0

Browse files
committed
Add LiveCharts2 page to example
1 parent 7aece3f commit a921ca0

File tree

10 files changed

+71
-4
lines changed

10 files changed

+71
-4
lines changed

src/CSharpMarkup.WinUI.Examples/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageVersion Include="CSharpMarkup.WinUI" Version="3.1.2" />
12+
<PackageVersion Include="CSharpMarkup.WinUI.LiveChartsCore.SkiaSharpView" Version="3.1.2" />
1213
<PackageVersion Include="CSharpMarkup.WinUI.ScottPlot" Version="3.1.2" />
1314
<PackageVersion Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation" Version="3.1.2" />
1415
<PackageVersion Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation.Toolkit" Version="3.1.2" />

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/Core/GlobalUsings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
global using static CSharpMarkup.WinUI.Uno.Extensions.Navigation.Helpers;
2727
global using static CSharpMarkup.WinUI.Uno.Extensions.Navigation.Toolkit.Helpers;
2828
global using static CSharpMarkup.WinUI.Uno.Toolkit.Helpers;
29-
global using static CSharpMarkup.WinUI.ScottPlot.Helpers;
3029
global using static WinUICsMarkupExamples.Presentation.Core.MarkupHelpers;
3130

3231
// Aliases for WinUI namespaces and types
@@ -35,7 +34,7 @@
3534
global using UI = Microsoft.UI;
3635
global using UIBindable = Microsoft.UI.Xaml.Data.BindableAttribute;
3736
global using UIControls = Microsoft.UI.Xaml.Controls;
38-
global using UIScottPlot = ScottPlot.WinUI;
37+
global using UISp = ScottPlot.WinUI;
3938

4039
// - Non-view types, e.g. enums, don't need a UI prefix because they are not mirrored as types in the CSharpMarkup namespaces
4140
global using BindingMode = Microsoft.UI.Xaml.Data.BindingMode;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using CSharpMarkup.WinUI.LiveChartsCore.SkiaSharpView;
2+
using static CSharpMarkup.WinUI.LiveChartsCore.SkiaSharpView.Helpers;
3+
4+
namespace WinUICsMarkupExamples.Presentation.Example;
5+
6+
partial class LiveCharts2Page
7+
{
8+
enum Row { Header, Body }
9+
10+
public void BuildUI() => Content (
11+
Grid (
12+
Rows (
13+
(Row.Header, Auto),
14+
(Row.Body , Star)
15+
),
16+
17+
NavigationBar(
18+
TextBlock("LiveCharts2"),
19+
AppBarButton() .Icon("Images/forward") .Bind(vm?.ForwardCommand)
20+
) .Grid_Row(Row.Header),
21+
22+
CartesianChart(ZoomMode: LiveChartsCore.Measure.ZoomAndPanMode.X)
23+
.Series().Bind(vm?.SeriesCollection)
24+
.Grid_Row(Row.Body) .HVStretch()
25+
)
26+
) .Background(Microsoft.UI.Colors.White);
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace WinUICsMarkupExamples.Presentation.Example;
2+
3+
[UIBindable]
4+
public sealed partial class LiveCharts2Page : BasePage<LiveCharts2ViewModel>, IBuildUI
5+
{
6+
public LiveCharts2Page() => BuildUI();
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using LiveChartsCore;
2+
using LiveChartsCore.SkiaSharpView;
3+
4+
namespace WinUICsMarkupExamples.Presentation.Example;
5+
6+
public partial class LiveCharts2ViewModel(INavigator navigator) : BaseViewModel
7+
{
8+
public ISeries[] SeriesCollection { get; set; } = [
9+
new LineSeries<int>(Fetch())
10+
];
11+
12+
static int[] Fetch()
13+
{
14+
var values = new int[100];
15+
var r = new Random();
16+
var t = 0;
17+
18+
for (var i = 0; i < 100; i++)
19+
{
20+
t += r.Next(-90, 100);
21+
values[i] = t;
22+
}
23+
24+
return values;
25+
}
26+
27+
[RelayCommand] public async Task Forward() => await navigator.NavigateViewModelAsync<ScottPlotViewModel>(this);
28+
}

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/Example/Routes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static void Register(IViewRegistry views, IRouteRegistry routes)
88
new ViewMap(ViewModel: typeof(ShellViewModel)),
99
new ViewMap<SearchPage, SearchViewModel>(),
1010
new ViewMap<FlutterPage, FlutterViewModel>(),
11+
new ViewMap<LiveCharts2Page, LiveCharts2ViewModel>(),
1112
new ViewMap<ScottPlotPage, ScottPlotViewModel>()
1213
);
1314

@@ -17,6 +18,7 @@ public static void Register(IViewRegistry views, IRouteRegistry routes)
1718
{
1819
new RouteMap("Search", View: views.FindByViewModel<SearchViewModel>(), IsDefault:true),
1920
new RouteMap("Flutter", View: views.FindByViewModel<FlutterViewModel>()),
21+
new RouteMap("LiveCharts", View: views.FindByViewModel<LiveCharts2ViewModel>()),
2022
new RouteMap("ScottPlot", View: views.FindByViewModel<ScottPlotViewModel>())
2123
}
2224
)

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/Example/ScottPlotPage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using static CSharpMarkup.WinUI.ScottPlot.Helpers;
2+
13
namespace WinUICsMarkupExamples.Presentation.Example;
24

35
partial class ScottPlotPage

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/Example/ScottPlotPage.logic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed partial class ScottPlotPage : BasePage<ScottPlotViewModel>, IBuild
77
{
88
public ScottPlotPage() => BuildUI();
99

10-
void ExampleGraph(UIScottPlot.WinUIPlot winUIPlot)
10+
void ExampleGraph(UISp.WinUIPlot winUIPlot)
1111
{
1212
var plot = winUIPlot.Plot;
1313
plot.Title("Example Graph");

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/Example/SearchViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public sealed partial class SearchViewModel(INavigator navigator) : BaseViewMode
113113

114114
public static Uri LinkUri(string linkText) => new(linkText.StartsWith("#", StringComparison.Ordinal) ? TwitterSearchUri(linkText) : linkText);
115115

116-
[RelayCommand] public async Task Forward() => await navigator.NavigateViewModelAsync<ScottPlotViewModel>(this);
116+
[RelayCommand] public async Task Forward() => await navigator.NavigateViewModelAsync<LiveCharts2ViewModel>(this);
117117
[RelayCommand] public async Task Search() => await LaunchUri(TwitterSearchUri(SearchText));
118118
[RelayCommand] public static void Like(Tweet tweet) => tweet.IsLikedByMe = !tweet.IsLikedByMe;
119119

src/CSharpMarkup.WinUI.Examples/WinUICsMarkupExamples.Presentation/WinUICsMarkupExamples.Presentation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<ItemGroup>
2424
<PackageReference Include="CSharpMarkup.WinUI" />
25+
<PackageReference Include="CSharpMarkup.WinUI.LiveChartsCore.SkiaSharpView" />
2526
<PackageReference Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation" />
2627
<PackageReference Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation.Toolkit" />
2728
<PackageReference Include="CSharpMarkup.WinUI.Uno.Toolkit" />

0 commit comments

Comments
 (0)