Skip to content

Commit 6557f4f

Browse files
committed
Maui tweaks
1 parent d7dab27 commit 6557f4f

File tree

8 files changed

+35
-54
lines changed

8 files changed

+35
-54
lines changed

src/MAUI/App.xaml.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@ public App()
77
InitializeComponent();
88
}
99

10-
protected override Window CreateWindow(IActivationState activationState)
11-
{
12-
this.MainPage ??= activationState?.Context.Services.GetRequiredService<AppShell>();
13-
14-
return base.CreateWindow(activationState);
15-
}
10+
protected override Window CreateWindow(IActivationState activationState) => new Window(activationState?.Context.Services.GetRequiredService<AppShell>() ?? new AppShell());
1611
}

src/MAUI/Commands/BeginEditCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ public class BeginEditCommand : DataGridCommand
77
{
88
public BeginEditCommand()
99
{
10-
this.Id = DataGridCommandId.BeginEdit;
10+
Id = DataGridCommandId.BeginEdit;
1111
}
1212

1313
public override void Execute(object parameter)
1414
{
15-
if (parameter is EditContext context)
16-
{
17-
Debug.WriteLine($"BeginEdit on: {context.CellInfo.Value} via {context.TriggerAction}.");
15+
if (parameter is not EditContext context)
16+
return;
1817

19-
this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.BeginEdit, parameter);
20-
}
18+
Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.BeginEdit, parameter);
19+
20+
Debug.WriteLine($"BeginEdit on: {context.CellInfo.Value} via {context.TriggerAction}.");
2121
}
2222
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommonHelpers.Models;
22
using System.Collections;
3-
using System.Diagnostics;
43
using Telerik.Maui.Controls.DataGrid;
54

65
namespace MauiDemo.Commands;
@@ -11,22 +10,20 @@ public CellTapUserCommand()
1110
{
1211
Id = DataGridCommandId.CellTap;
1312
}
13+
1414
public override bool CanExecute(object parameter)
1515
{
1616
return true;
1717
}
18+
1819
public override void Execute(object parameter)
1920
{
20-
if (parameter is not DataGridCellInfo context)
21+
if (parameter is not DataGridCellInfo { Item: Employee rowValue } context)
2122
return;
2223

23-
var cellValue = context.Value;
24-
var cellColumn = context.Column;
25-
var rowValue = context.Item as Employee;
24+
var dv = context.Column.DataGrid.GetDataView();
2625

27-
var dv = cellColumn.DataGrid.GetDataView();
28-
29-
var index = 0;
26+
int index;
3027

3128
if (dv.Items is IList list)
3229
{
@@ -37,17 +34,10 @@ public override void Execute(object parameter)
3734
// Fallback: convert to list and search, or handle groupings, etc
3835
var itemsList = dv.Items.ToList();
3936
index = itemsList.IndexOf(rowValue);
40-
41-
42-
4337
}
4438

45-
var message = $"You tapped on {cellValue} inside {context.Column.HeaderText} column, which is index {index}!";
46-
47-
Debug.WriteLine(message);
48-
49-
App.Current?.MainPage?.DisplayAlert("CellTap Command: ", message, "OK");
39+
Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CellTap, parameter);
5040

51-
this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CellTap, parameter);
41+
Shell.Current.DisplayAlert("CellTap Command: ", $"You tapped on {context.Value} inside {context.Column.HeaderText} column, which is index {index}!", "OK");
5242
}
5343
}

src/MAUI/Commands/CommitEditCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ public class CommitEditCommand : DataGridCommand
77
{
88
public CommitEditCommand()
99
{
10-
this.Id = DataGridCommandId.CommitEdit;
10+
Id = DataGridCommandId.CommitEdit;
1111
}
1212

1313
public override void Execute(object parameter)
1414
{
15-
if (parameter is EditContext context)
16-
{
17-
Debug.WriteLine($"CommitEdit on: {context.CellInfo.Value} via {context.TriggerAction}.");
15+
if (parameter is not EditContext context)
16+
return;
1817

19-
this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CommitEdit, parameter);
20-
}
18+
Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CommitEdit, parameter);
19+
20+
Debug.WriteLine($"CommitEdit on: {context.CellInfo.Value} via {context.TriggerAction}.");
2121
}
2222
}

src/MAUI/MauiDemo.csproj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<SingleProject>true</SingleProject>
99
<ImplicitUsings>enable</ImplicitUsings>
1010

11-
<MauiVersion>9.0.40</MauiVersion>
11+
<!--<MauiVersion>9.0.40</MauiVersion>-->
12+
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>
1213

1314
<!-- Display name -->
1415
<ApplicationTitle>MauiDemo</ApplicationTitle>
@@ -41,10 +42,6 @@
4142
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
4243
</PropertyGroup>
4344

44-
<!--<PropertyGroup>
45-
<UseTelerikTheming>true</UseTelerikTheming>
46-
</PropertyGroup>-->
47-
4845
<ItemGroup>
4946
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
5047
<MauiIcon Include="Resources\AppIcon\appiconfg.svg" />
@@ -59,12 +56,10 @@
5956
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.110" />
6057
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" />
6158
<PackageReference Include="CommonHelpers" Version="1.5.1" />
62-
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
63-
<PackageReference Include="Telerik.Licensing" Version="1.6.24" />
6459
<PackageReference Include="Telerik.UI.for.Maui" Version="11.1.0" />
6560
</ItemGroup>
6661

6762
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
68-
<PackageReference Include="WinUIEx" Version="2.8.0" />
63+
<PackageReference Include="WinUIEx" Version="2.7.0" />
6964
</ItemGroup>
7065
</Project>

src/MAUI/Models/DataTypeEditorsModel.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public class DataTypeEditorsModel : NotifyPropertyChangedBase
1414
private string phoneNumber;
1515
private string email;
1616
private string password;
17-
private string? url;
17+
private string url;
1818
private decimal? cost;
19-
private string? notes;
19+
private string notes;
2020
private TimeSpan? duration;
2121
private EnumValue accommodation = EnumValue.Apartment;
22+
2223
public enum EnumValue
2324
{
2425
SingleRoom,
@@ -103,10 +104,7 @@ public double? People
103104
[Display(Name = "Select accomodation")]
104105
public EnumValue Accommodation
105106
{
106-
get
107-
{
108-
return accommodation;
109-
}
107+
get => accommodation;
110108
set
111109
{
112110
if (accommodation != value)
@@ -134,7 +132,7 @@ public TimeSpan? Duration
134132
[Display(Name = "Web address")]
135133
[DataType(DataType.Url)]
136134
[RegularExpression(@"^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$", ErrorMessage = "Please enter valid url.")]
137-
public string? URL
135+
public string Url
138136
{
139137
get => url;
140138
set => UpdateValue(ref url, value);
@@ -151,7 +149,7 @@ public decimal? Cost
151149

152150
[Display(Name = "Notes")]
153151
[DataType(DataType.MultilineText)]
154-
public string? Notes
152+
public string Notes
155153
{
156154
get => notes;
157155
set => UpdateValue(ref notes, value);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using MauiDemo.Models;
2+
13
namespace MauiDemo.Views;
24

35
public partial class DataFormPage : ContentPage
46
{
57
public DataFormPage()
68
{
79
InitializeComponent();
8-
}
10+
MyDataForm.BindingContext = new DataTypeEditorsModel();
11+
}
912
}

src/MAUI/Views/MainPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
EventName="Appearing" />
1414
</ContentPage.Behaviors>
1515

16-
<Grid RowDefinitions="Auto,*,Auto" Style="{StaticResource FillGridStyle}">
17-
<Grid Background="{Binding BackgroundColor, Source={x:Reference MyToolbar}}">
16+
<Grid RowDefinitions="Auto,*,Auto" Style="{StaticResource FillGridStyle}" >
17+
<Grid BackgroundColor="{Binding BackgroundColor, Source={x:Reference MyToolbar}, x:DataType=Color}">
1818
<telerik:RadToolbar x:Name="MyToolbar"
1919
Style="{StaticResource CenterToolbarStyle}">
2020
<telerik:ButtonToolbarItem Text="Button">

0 commit comments

Comments
 (0)