Skip to content

Commit

Permalink
chore: Use ContentTemplate and windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Nov 23, 2023
1 parent 833e43c commit 7369131
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:hlp="using:Uno.Toolkit.UI.Helpers"
xmlns:helpers="using:Uno.Toolkit.UI.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
mc:Ignorable="d"
Expand All @@ -23,13 +23,13 @@
</StackPanel.Resources>
<utu:ResponsiveView>
<utu:ResponsiveView.ResponsiveLayout>
<hlp:ResponsiveLayout>
<hlp:ResponsiveLayout.Narrowest>150</hlp:ResponsiveLayout.Narrowest>
<hlp:ResponsiveLayout.Narrow>1100</hlp:ResponsiveLayout.Narrow>
<hlp:ResponsiveLayout.Normal>1300</hlp:ResponsiveLayout.Normal>
<hlp:ResponsiveLayout.Wide>1400</hlp:ResponsiveLayout.Wide>
<hlp:ResponsiveLayout.Widest>1500</hlp:ResponsiveLayout.Widest>
</hlp:ResponsiveLayout>
<helpers:ResponsiveLayout>
<helpers:ResponsiveLayout.Narrowest>200</helpers:ResponsiveLayout.Narrowest>
<helpers:ResponsiveLayout.Narrow>350</helpers:ResponsiveLayout.Narrow>
<helpers:ResponsiveLayout.Normal>800</helpers:ResponsiveLayout.Normal>
<helpers:ResponsiveLayout.Wide>1200</helpers:ResponsiveLayout.Wide>
<helpers:ResponsiveLayout.Widest>1500</helpers:ResponsiveLayout.Widest>
</helpers:ResponsiveLayout>
</utu:ResponsiveView.ResponsiveLayout>
<utu:ResponsiveView.NarrowestContent>
<DataTemplate>
Expand Down
29 changes: 13 additions & 16 deletions src/Uno.Toolkit.UI/Controls/ResponsiveView/ResponsiveView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

namespace Uno.Toolkit.UI;

public partial class ResponsiveView : ContentControl
#if !WINDOWS_UWP
, IResponsiveCallback
#endif
public partial class ResponsiveView : ContentControl, IResponsiveCallback
{
#region DependencyProperties

Expand Down Expand Up @@ -100,9 +97,13 @@ public ResponsiveView()

private void ResponsiveView_Loaded(object sender, RoutedEventArgs e)
{
var contentToSet = GetInitialValue();
var dataTemplate = GetInitialValue();

SetContent(contentToSet);
#if WINDOWS || WINDOWS_UWP
Content = dataTemplate?.LoadContent() as UIElement;
#else
ContentTemplate = dataTemplate;
#endif
}

private DataTemplate? GetInitialValue()
Expand Down Expand Up @@ -130,16 +131,12 @@ private void ResponsiveView_Loaded(object sender, RoutedEventArgs e)

public void OnSizeChanged(Size size, ResponsiveLayout layout)
{
var contentToSet = GetValueForSize(size, ResponsiveLayout ?? layout);

SetContent(contentToSet);
}
var dataTemplate = GetValueForSize(size, ResponsiveLayout ?? layout);

private void SetContent(DataTemplate? contentToSet)
{
if (contentToSet is not null)
{
Content = contentToSet.LoadContent() as UIElement;
}
#if WINDOWS || WINDOWS_UWP
Content = dataTemplate?.LoadContent() as UIElement;
#else
ContentTemplate = dataTemplate;
#endif
}
}
60 changes: 0 additions & 60 deletions src/Uno.Toolkit.UI/Controls/ResponsiveView/ResponsiveView.xaml

This file was deleted.

0 comments on commit 7369131

Please sign in to comment.