Skip to content

Commit ee8e185

Browse files
committed
Add ScottPlot example
1 parent f028524 commit ee8e185

File tree

10 files changed

+60
-6
lines changed

10 files changed

+60
-6
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.ScottPlot" Version="3.1.2" />
1213
<PackageVersion Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation" Version="3.1.2" />
1314
<PackageVersion Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation.Toolkit" Version="3.1.2" />
1415
<PackageVersion Include="CSharpMarkup.WinUI.Uno.Toolkit" Version="3.1.2" />

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
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;
2930
global using static WinUICsMarkupExamples.Presentation.Core.MarkupHelpers;
3031

3132
// Aliases for WinUI namespaces and types
@@ -34,6 +35,9 @@
3435
global using UI = Microsoft.UI;
3536
global using UIBindable = Microsoft.UI.Xaml.Data.BindableAttribute;
3637
global using UIControls = Microsoft.UI.Xaml.Controls;
38+
global using SpLib = ScottPlot;
39+
global using SpUI = ScottPlot.WinUI;
40+
3741
// - Non-view types, e.g. enums, don't need a UI prefix because they are not mirrored as types in the CSharpMarkup namespaces
3842
global using BindingMode = Microsoft.UI.Xaml.Data.BindingMode;
3943
global using Visibility = Microsoft.UI.Xaml.Visibility;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ public static void Register(IViewRegistry views, IRouteRegistry routes)
77
views.Register(
88
new ViewMap(ViewModel: typeof(ShellViewModel)),
99
new ViewMap<SearchPage, SearchViewModel>(),
10-
new ViewMap<FlutterPage, FlutterViewModel>()
10+
new ViewMap<FlutterPage, FlutterViewModel>(),
11+
new ViewMap<ScottPlotPage, ScottPlotViewModel>()
1112
);
1213

1314
routes.Register(
1415
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
1516
Nested: new RouteMap[]
1617
{
1718
new RouteMap("Search", View: views.FindByViewModel<SearchViewModel>(), IsDefault:true),
18-
new RouteMap("Flutter", View: views.FindByViewModel<FlutterViewModel>())
19+
new RouteMap("Flutter", View: views.FindByViewModel<FlutterViewModel>()),
20+
new RouteMap("ScottPlot", View: views.FindByViewModel<ScottPlotViewModel>())
1921
}
2022
)
2123
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace WinUICsMarkupExamples.Presentation.Example;
2+
3+
partial class ScottPlotPage
4+
{
5+
enum Row { Header, Body }
6+
7+
public void BuildUI() => Content (
8+
Grid (
9+
Rows (
10+
(Row.Header, Auto),
11+
(Row.Body , Star)
12+
),
13+
14+
NavigationBar(
15+
TextBlock("ScottPlot"),
16+
AppBarButton() .Icon("Images/forward") .Bind(vm?.ForwardCommand)
17+
) .Grid_Row(Row.Header),
18+
19+
WinUIPlot() .Invoke(ExampleGraph)
20+
.Grid_Row(Row.Body) .HVStretch()
21+
)
22+
);
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using ScottPlot;
2+
3+
namespace WinUICsMarkupExamples.Presentation.Example;
4+
5+
[UIBindable]
6+
public sealed partial class ScottPlotPage : BasePage<ScottPlotViewModel>, IBuildUI
7+
{
8+
public ScottPlotPage() => BuildUI();
9+
10+
void ExampleGraph(SpUI.WinUIPlot plot)
11+
{
12+
plot.Plot.Title("Example Graph");
13+
plot.Plot.Add.Signal(Generate.Sin(51));
14+
plot.Plot.Add.Signal(Generate.Cos(51));
15+
plot.Refresh();
16+
}
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace WinUICsMarkupExamples.Presentation.Example;
2+
3+
public partial class ScottPlotViewModel(INavigator navigator) : BaseViewModel
4+
{
5+
[RelayCommand] public async Task Forward() => await navigator.NavigateViewModelAsync<FlutterViewModel>(this);
6+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Footer .Grid_Row(2)
1616

1717
NavigationBar Header => NavigationBar(
1818
TextBox(PlaceholderText: "Search") .Style(ThemeResource.ComboBoxTextBoxStyle) .VerticalAlignment().Center() .Bind(vm?.SearchText, BindingMode.TwoWay),
19-
AppBarButton() .Icon("Images/search" ) .OnClick(vm!.SearchCommand),
20-
AppBarButton() .Icon("Images/forward") .OnClick(vm!.ForwardCommand)
19+
AppBarButton() .Icon("Images/search" ) .Bind(vm?.SearchCommand),
20+
AppBarButton() .Icon("Images/forward") .Bind(vm?.ForwardCommand)
2121
) .HorizontalContentAlignment().Stretch()
2222
#if HAS_UNO
2323
.Style().AppResource("XamlDefaultNavigationBar")

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<FlutterViewModel>(this);
116+
[RelayCommand] public async Task Forward() => await navigator.NavigateViewModelAsync<ScottPlotViewModel>(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
@@ -25,5 +25,6 @@
2525
<PackageReference Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation" />
2626
<PackageReference Include="CSharpMarkup.WinUI.Uno.Extensions.Navigation.Toolkit" />
2727
<PackageReference Include="CSharpMarkup.WinUI.Uno.Toolkit" />
28+
<PackageReference Include="CSharpMarkup.WinUI.ScottPlot" />
2829
</ItemGroup>
2930
</Project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Uno.Sdk">
1+
<Project Sdk="Uno.Sdk">
22
<ItemGroup>
33
<ProjectReference Include="..\WinUICsMarkupExamples.Presentation\WinUICsMarkupExamples.Presentation.csproj" />
44
</ItemGroup>

0 commit comments

Comments
 (0)