Skip to content

Commit e2b8f08

Browse files
committed
Fix ElementGroup AOT
1 parent 0fcdecd commit e2b8f08

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

dev/DevWinUI.Controls/Controls/Others/ElementGroup.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.UI.Xaml.Markup;
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.UI.Xaml.Markup;
23

34
namespace DevWinUI;
45
public partial class ElementGroup : ItemsControl
@@ -21,15 +22,16 @@ private static void OnOrientationChanged(DependencyObject d, DependencyPropertyC
2122
}
2223
}
2324

25+
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ItemsPanelTemplate))]
2426
private void UpdateOrientation()
2527
{
2628
if (Orientation == Orientation.Horizontal)
2729
{
28-
ItemsPanel = (ItemsPanelTemplate)XamlReader.Load("<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><StackPanel Orientation='Horizontal'/></ItemsPanelTemplate>");
30+
ItemsPanel = Application.Current.Resources["ElementGroupHorizontalItemsPanel"] as ItemsPanelTemplate;
2931
}
3032
else
3133
{
32-
ItemsPanel = (ItemsPanelTemplate)XamlReader.Load("<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><StackPanel Orientation='Vertical'/></ItemsPanelTemplate>");
34+
ItemsPanel = Application.Current.Resources["ElementGroupVerticalItemsPanel"] as ItemsPanelTemplate;
3335
}
3436
UpdateElements();
3537
}

dev/DevWinUI.Controls/Themes/Styles/CommonStyles/Common.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="using:DevWinUI">
44

5+
<ItemsPanelTemplate x:Key="ElementGroupHorizontalItemsPanel">
6+
<StackPanel Orientation="Horizontal" />
7+
</ItemsPanelTemplate>
8+
<ItemsPanelTemplate x:Key="ElementGroupVerticalItemsPanel">
9+
<StackPanel Orientation="Vertical" />
10+
</ItemsPanelTemplate>
11+
512
<ThemeShadow x:Name="ThemeShadow" />
613
<x:Double x:Key="SettingActionControlMinWidth">240</x:Double>
714

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DevWinUIGallery.Views;
1+
using WinRT;
2+
3+
namespace DevWinUIGallery.Views;
24

35
public sealed partial class ElementGroupPage : Page
46
{
@@ -11,7 +13,7 @@ private void CmbOrientation_SelectionChanged(object sender, SelectionChangedEven
1113
{
1214
if (ElementGroupSample != null && ElementGroupSample2 != null && ElementGroupSample3 != null)
1315
{
14-
var item = CmbOrientation.SelectedItem as ComboBoxItem;
16+
var item = CmbOrientation.SelectedItem.As<ComboBoxItem>();
1517
var orientation = GeneralHelper.GetEnum<Orientation>(item.Tag.ToString());
1618
ElementGroupSample.Orientation = orientation;
1719
ElementGroupSample2.Orientation = orientation;

0 commit comments

Comments
 (0)