Skip to content

Commit

Permalink
fix(RadioButtons): Fix MaxColumns is not bound properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 10, 2021
1 parent e8cb04c commit 68c72c8
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<UserControl
x:Class="Uno.UI.Tests.Windows_UI_XAML_Controls.RadioButtonsTests.Controls.When_RadioButtons_TemplateBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.UI.Tests.Windows_UI_XAML_Controls.RadioButtonsTests.Controls"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:primitives="using:Microsoft.UI.Xaml.Controls.Primitives"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
<Style x:Key="MyStyle" TargetType="muxc:RadioButtons">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="muxc:RadioButtons">
<StackPanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="HeaderContentPresenter.Foreground" Value="{ThemeResource RadioButtonsHeaderForegroundDisabled}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="HeaderContentPresenter"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Foreground="{ThemeResource RadioButtonsHeaderForeground}"
Margin="{ThemeResource RadioButtonsTopHeaderMargin}"/>
<muxc:ItemsRepeater x:Name="InnerRepeater">
<muxc:ItemsRepeater.Layout>
<primitives:ColumnMajorUniformToLargestGridLayout x:Name="InnerLayout"
MaxColumns="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MaxColumns}"
ColumnSpacing="{ThemeResource RadioButtonsColumnSpacing}"
RowSpacing="{ThemeResource RadioButtonsRowSpacing}"/>
</muxc:ItemsRepeater.Layout>
</muxc:ItemsRepeater>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<StackPanel Grid.Row="1" Orientation="Vertical">
<muxc:RadioButtons x:Name="rootRB" x:FieldModifier="public" MaxColumns="2" Style="{StaticResource MyStyle}">
</muxc:RadioButtons>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace Uno.UI.Tests.Windows_UI_XAML_Controls.RadioButtonsTests.Controls
{
public sealed partial class When_RadioButtons_TemplateBinding : UserControl
{
public When_RadioButtons_TemplateBinding()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uno.UI.Tests.Windows_UI_XAML_Controls.RadioButtonsTests.Controls;

namespace Uno.UI.Tests.Windows_UI_XAML_Controls.RadioButtonsTests
{
[TestClass]
public class Given_RadioButtons
{
[TestMethod]
public void When_TemplateBinding()
{
var SUT = new When_RadioButtons_TemplateBinding();
SUT.ForceLoaded();

var repeater = SUT.FindName("InnerRepeater") as ItemsRepeater;
Assert.IsNotNull(repeater);

var layout = repeater.Layout as ColumnMajorUniformToLargestGridLayout;

Assert.AreEqual(2, layout.MaxColumns);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public object ItemTemplate

#region Layout (DP - With default callback)
public static DependencyProperty LayoutProperty { get; } = DependencyProperty.Register(
"Layout", typeof(Layout), typeof(ItemsRepeater), new PropertyMetadata(new StackLayout(), OnPropertyChanged));
"Layout", typeof(Layout), typeof(ItemsRepeater), new FrameworkPropertyMetadata(
defaultValue: new StackLayout(),
propertyChangedCallback: OnPropertyChanged
));

#if __ANDROID__ || __MACOS__
public new Layout Layout
Expand Down

0 comments on commit 68c72c8

Please sign in to comment.