Skip to content

Commit 9502c54

Browse files
committed
Fix Some AOT Warning for GalleryApp
1 parent 9fffec0 commit 9502c54

10 files changed

Lines changed: 123 additions & 57 deletions

dev/DevWinUI.Gallery/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ private static IServiceProvider ConfigureServices()
3131
services.AddSingleton<IJsonNavigationService, JsonNavigationService>();
3232

3333
services.AddTransient<MainViewModel>();
34+
services.AddTransient<ExtensionViewModel>();
35+
services.AddTransient<SwitchPresenterViewModel>();
3436
services.AddTransient<GeneralSettingViewModel>();
3537
services.AddTransient<AppUpdateSettingViewModel>();
3638
services.AddTransient<AboutUsSettingViewModel>();

dev/DevWinUI.Gallery/DevWinUI.Gallery.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<EnableMsixTooling>true</EnableMsixTooling>
1010
<TrimMode>partial</TrimMode>
1111
<ImplicitUsings>true</ImplicitUsings>
12-
<LangVersion>Latest</LangVersion>
12+
<LangVersion>preview</LangVersion>
1313
<IsAotCompatible>True</IsAotCompatible>
1414
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
1515
<WindowsPackageType Condition="'$(GITHUB_ACTIONS)'=='true'">None</WindowsPackageType>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace DevWinUIGallery.ViewModels;
4+
5+
public partial class ExtensionViewModel : ObservableObject
6+
{
7+
[ObservableProperty]
8+
public partial ObservableCollection<Animal> Items { get; set; } = new ObservableCollection<Animal>(Enum.GetValues<Animal>());
9+
10+
[ObservableProperty]
11+
public partial bool IsCharacterValid {get; set;}
12+
13+
[ObservableProperty]
14+
public partial bool IsPhoneNumberValid { get; set; }
15+
16+
[ObservableProperty]
17+
public partial bool IsEmailValid { get; set; }
18+
19+
[ObservableProperty]
20+
public partial bool IsDecimalValid { get; set; }
21+
22+
[ObservableProperty]
23+
public partial bool IsNumberValid { get; set; }
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace DevWinUIGallery.ViewModels;
4+
5+
public partial class SwitchPresenterViewModel : ObservableObject
6+
{
7+
[ObservableProperty]
8+
public partial RadioButton RadioSelectedItem { get; set; }
9+
10+
[ObservableProperty]
11+
public partial ObservableCollection<Animal> Items { get; set; } = new ObservableCollection<Animal>(Enum.GetValues<Animal>());
12+
}

dev/DevWinUI.Gallery/Views/Pages/Features/ExtensionPage.xaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<StackPanel Margin="10"
3737
Spacing="10">
3838
<ComboBox MinWidth="200"
39-
ItemsSource="{x:Bind Items, Mode=OneWay}"
39+
ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
4040
SelectedIndex="0" />
4141
</StackPanel>
4242
</local:ControlExample>
@@ -48,47 +48,52 @@
4848
Spacing="10">
4949
<TextBox Name="PhoneNumberValidator"
5050
dev:TextBoxExtensions.Regex="^\s*\+?\s*([0-9][\s-]*){9,}$"
51-
Header="Text box with Regex extension for phone number, validation occurs on TextChanged" />
51+
Header="Text box with Regex extension for phone number, validation occurs on TextChanged"
52+
TextChanging="PhoneNumberValidator_TextChanging" />
5253
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}">
5354
<Run Text="Is valid: " />
5455
<Run FontWeight="SemiBold"
55-
Text="{Binding (dev:TextBoxExtensions.IsValid), ElementName=PhoneNumberValidator}" />
56+
Text="{x:Bind ViewModel.IsPhoneNumberValid, Mode=OneWay}" />
5657
</TextBlock>
5758
<TextBox Name="CharactValidator"
5859
dev:TextBoxExtensions.ValidationMode="Dynamic"
5960
dev:TextBoxExtensions.ValidationType="Characters"
6061
Header="Text box with ValidationType=Characters, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
61-
Text="abcdef" />
62+
Text="abcdef"
63+
TextChanging="CharactValidator_TextChanging" />
6264
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}">
6365
<Run Text="Is valid: " />
6466
<Run FontWeight="SemiBold"
65-
Text="{Binding (dev:TextBoxExtensions.IsValid), ElementName=CharactValidator}" />
67+
Text="{x:Bind ViewModel.IsCharacterValid, Mode=OneWay}" />
6668
</TextBlock>
6769
<TextBox Name="EmailValidator"
6870
dev:TextBoxExtensions.ValidationType="Email"
69-
Header="Text box with ValidationType=Email, validation occurs on TextChanged" />
71+
Header="Text box with ValidationType=Email, validation occurs on TextChanged"
72+
TextChanging="EmailValidator_TextChanging" />
7073
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}">
7174
<Run Text="Is valid: " />
7275
<Run FontWeight="SemiBold"
73-
Text="{Binding (dev:TextBoxExtensions.IsValid), ElementName=EmailValidator}" />
76+
Text="{x:Bind ViewModel.IsEmailValid, Mode=OneWay}" />
7477
</TextBlock>
7578
<TextBox Name="DecimalValidatorForce"
7679
dev:TextBoxExtensions.ValidationMode="Forced"
7780
dev:TextBoxExtensions.ValidationType="Decimal"
78-
Header="Text box with ValidationType=Decimal, validation occurs on TextChanged and force occurs on lose focus with ValidationMode=Force (333,111 or 333.111)" />
81+
Header="Text box with ValidationType=Decimal, validation occurs on TextChanged and force occurs on lose focus with ValidationMode=Force (333,111 or 333.111)"
82+
TextChanging="DecimalValidatorForce_TextChanging" />
7983
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}">
8084
<Run Text="Is valid: " />
8185
<Run FontWeight="SemiBold"
82-
Text="{Binding (dev:TextBoxExtensions.IsValid), ElementName=DecimalValidatorForce}" />
86+
Text="{x:Bind ViewModel.IsDecimalValid, Mode=OneWay}" />
8387
</TextBlock>
8488
<TextBox Name="NumberValidatorDynamic"
8589
dev:TextBoxExtensions.ValidationMode="Dynamic"
8690
dev:TextBoxExtensions.ValidationType="Number"
87-
Header="Text box with ValidationType=Number, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid" />
91+
Header="Text box with ValidationType=Number, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
92+
TextChanging="NumberValidatorDynamic_TextChanging" />
8893
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}">
8994
<Run Text="Is valid: " />
9095
<Run FontWeight="SemiBold"
91-
Text="{Binding (dev:TextBoxExtensions.IsValid), ElementName=NumberValidatorDynamic}" />
96+
Text="{x:Bind ViewModel.IsNumberValid, Mode=OneWay}" />
9297
</TextBlock>
9398
</StackPanel>
9499
</local:ControlExample>
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
using System.Collections.ObjectModel;
2-
3-
namespace DevWinUIGallery.Views;
1+
namespace DevWinUIGallery.Views;
42

53
public sealed partial class ExtensionPage : Page
64
{
7-
public ObservableCollection<Animal> Items
5+
public ExtensionViewModel ViewModel { get; }
6+
public ExtensionPage()
87
{
9-
get { return (ObservableCollection<Animal>)GetValue(ItemsProperty); }
10-
set { SetValue(ItemsProperty, value); }
8+
ViewModel = App.GetService<ExtensionViewModel>();
9+
this.InitializeComponent();
1110
}
1211

13-
public static readonly DependencyProperty ItemsProperty =
14-
DependencyProperty.Register(nameof(Items), typeof(ObservableCollection<Animal>), typeof(ExtensionPage), new PropertyMetadata(new ObservableCollection<Animal>(Enum.GetValues<Animal>())));
12+
private void PhoneNumberValidator_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
13+
{
14+
ViewModel.IsPhoneNumberValid = TextBoxExtensions.GetIsValid(sender);
15+
}
1516

16-
public ExtensionPage()
17+
private void CharactValidator_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
1718
{
18-
this.InitializeComponent();
19+
ViewModel.IsCharacterValid = TextBoxExtensions.GetIsValid(sender);
20+
}
21+
22+
private void EmailValidator_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
23+
{
24+
ViewModel.IsEmailValid = TextBoxExtensions.GetIsValid(sender);
25+
}
26+
27+
private void DecimalValidatorForce_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
28+
{
29+
ViewModel.IsDecimalValid = TextBoxExtensions.GetIsValid(sender);
30+
}
31+
32+
private void NumberValidatorDynamic_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
33+
{
34+
ViewModel.IsNumberValid = TextBoxExtensions.GetIsValid(sender);
1935
}
2036
}

dev/DevWinUI.Gallery/Views/Pages/Features/GoToTopPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
VerticalAlignment="Bottom"
3838
Animated="True"
3939
AutoHiding="True"
40-
Target="{Binding ElementName=ScrollViewerSample}" />
40+
Target="{x:Bind ScrollViewerSample, Mode=OneWay}" />
4141
</Grid>
4242
</local:ControlExample>
4343
<local:ControlExample DocPage="controls/goToTop"
@@ -65,7 +65,7 @@
6565
VerticalAlignment="Bottom"
6666
Animated="True"
6767
AutoHiding="True"
68-
Target="{Binding ElementName=ScrollViewSample}" />
68+
Target="{x:Bind ScrollViewSample, Mode=OneWay}" />
6969
</Grid>
7070
</local:ControlExample>
7171
</StackPanel>

dev/DevWinUI.Gallery/Views/Pages/Features/SwitchPresenterPage.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@
105105
<TextBox Name="CodeValidator"
106106
dev:TextBoxExtensions.Regex="{x:Bind Regex, Mode=OneWay}"
107107
Header="{x:Bind Header, Mode=OneWay}"
108-
PlaceholderText="{x:Bind PlaceholderText, Mode=OneWay}" />
108+
PlaceholderText="{x:Bind PlaceholderText, Mode=OneWay}"
109+
TextChanging="CodeValidator_TextChanging" />
109110
<TextBlock Text="Thanks for entering a valid code!"
110-
Visibility="{Binding (dev:TextBoxExtensions.IsValid), ElementName=CodeValidator}" />
111+
Visibility="Collapsed" />
111112
</StackPanel>
112113
</DataTemplate>
113114
</dev:SwitchPresenter.ContentTemplate>
@@ -179,8 +180,9 @@
179180
HeaderText="Example 1"
180181
XamlSource="Features/SwitchPresenter/SwitchPresenterPage_Part1_xaml.txt">
181182
<local:ControlExample.Pane>
182-
<RadioButtons x:Name="radio"
183-
Header="Options">
183+
<RadioButtons Header="Options"
184+
SelectedIndex="0"
185+
SelectedItem="{x:Bind ViewModel.RadioSelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
184186
<RadioButton Content="Square"
185187
Tag="square" />
186188
<RadioButton Content="Circle"
@@ -192,12 +194,11 @@
192194
<StackPanel Margin="10"
193195
Spacing="10">
194196
<dev:SwitchPresenter Grid.Row="1"
195-
Value="{Binding SelectedItem.Tag, ElementName=radio}">
197+
Value="{x:Bind ViewModel.RadioSelectedItem.Tag, Mode=OneWay}">
196198
<dev:Case Value="square">
197199
<StackPanel animations:Implicit.HideAnimations="{StaticResource HideTransitions}"
198200
animations:Implicit.ShowAnimations="{StaticResource ShowTransitions}"
199201
Style="{StaticResource PanelStyle}">
200-
201202
<Border Width="24"
202203
Height="24"
203204
Background="{ThemeResource AccentFillColorDefaultBrush}" />
@@ -239,7 +240,7 @@
239240
<local:ControlExample.Pane>
240241
<ComboBox x:Name="AnimalPicker"
241242
Header="Pick an Animal"
242-
ItemsSource="{x:Bind Items, Mode=OneWay}" />
243+
ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}" />
243244
</local:ControlExample.Pane>
244245
<StackPanel>
245246
<dev:SwitchPresenter Padding="16"

dev/DevWinUI.Gallery/Views/Pages/Features/SwitchPresenterPage.xaml.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
using System.Collections.ObjectModel;
2-
3-
namespace DevWinUIGallery.Views;
1+
namespace DevWinUIGallery.Views;
42
public sealed partial class SwitchPresenterPage : Page
53
{
6-
public ObservableCollection<Animal> Items
4+
public SwitchPresenterViewModel ViewModel { get; }
5+
public SwitchPresenterPage()
76
{
8-
get { return (ObservableCollection<Animal>)GetValue(ItemsProperty); }
9-
set { SetValue(ItemsProperty, value); }
7+
ViewModel = App.GetService<SwitchPresenterViewModel>();
8+
this.InitializeComponent();
109
}
1110

12-
public static readonly DependencyProperty ItemsProperty =
13-
DependencyProperty.Register(nameof(Items), typeof(ObservableCollection<Animal>), typeof(SwitchPresenterPage), new PropertyMetadata(new ObservableCollection<Animal>(Enum.GetValues<Animal>())));
14-
15-
public SwitchPresenterPage()
11+
private void CodeValidator_TextChanging(Microsoft.UI.Xaml.Controls.TextBox sender, TextBoxTextChangingEventArgs args)
1612
{
17-
this.InitializeComponent();
13+
if (sender.Parent is StackPanel stackPanel)
14+
{
15+
var textBlock = stackPanel.Children.OfType<TextBlock>().FirstOrDefault();
16+
if (textBlock != null)
17+
{
18+
bool isValid = TextBoxExtensions.GetIsValid(sender);
19+
textBlock.Visibility = isValid ? Visibility.Visible : Visibility.Collapsed;
20+
}
21+
}
1822
}
1923
}
2024

dev/DevWinUI.Gallery/Views/Pages/Win2d/GooeyPage.xaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
HeaderText="GooeyButton"
1919
XamlSource="Win2d/GooeyPage_xaml.txt">
2020

21-
<dev:GooeyButton x:Name="gooeyButton"
22-
HorizontalAlignment="Center"
23-
VerticalAlignment="Center"
24-
Invoked="gooeyButton_Invoked"
25-
ItemInvoked="gooeyButton_ItemInvoked"
26-
ItemsSource="{x:Bind strings}">
27-
<dev:GooeyButton.Content>
28-
<SymbolIcon Symbol="Add" />
29-
</dev:GooeyButton.Content>
30-
<dev:GooeyButton.ItemTemplate>
31-
<DataTemplate>
32-
<SymbolIcon Symbol="{Binding}" />
33-
</DataTemplate>
34-
</dev:GooeyButton.ItemTemplate>
35-
</dev:GooeyButton>
21+
<Grid Height="250">
22+
<dev:GooeyButton x:Name="gooeyButton"
23+
HorizontalAlignment="Center"
24+
VerticalAlignment="Bottom"
25+
Invoked="gooeyButton_Invoked"
26+
ItemInvoked="gooeyButton_ItemInvoked"
27+
ItemsSource="{x:Bind strings}">
28+
<dev:GooeyButton.Content>
29+
<SymbolIcon Symbol="Add" />
30+
</dev:GooeyButton.Content>
31+
<dev:GooeyButton.ItemTemplate>
32+
<DataTemplate x:DataType="Symbol">
33+
<SymbolIcon Symbol="{x:Bind}" />
34+
</DataTemplate>
35+
</dev:GooeyButton.ItemTemplate>
36+
</dev:GooeyButton>
37+
</Grid>
3638
</local:ControlExample>
3739

3840
<local:ControlExample DocPage="controls/gooey"

0 commit comments

Comments
 (0)