Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 2a97a6c

Browse files
hartezrmarinho
andauthored
Templated RadioButtons and RadioButtonGroups (#11628)
* First stab at RadioButtonGroup attached property and Templated RadioButton * RadioButtonGroupController assigning group names * Added updates for RadioButtonGroupController on selection change * More galleries! * Content property propagation * Ignore renderers if using templated views on UWP * Apply text/font properties to Content * Make RadioButton template parts constants * Cache renderer availability lookup * Add TemplateView check to CreateRenderer on iOS * Handle Checked RadioButton GroupName changes * Update WPF renderer * Update macOS and Tizen renderers * Add more unit tests, make RB Value updates propagate to RBG * Remove Text property, updated examples; throw Exception when Content is not Text and non-Text Content is not supported * Prevent Content exceptions in demo pages * Colors -> Brushes * Add default ControlTemplate example * Set up flags for Core Gallery test pages * Switch Android back to ToString for Content * Back to ToString where necessary, and using the WrapperControl for UWP * Add comment for Content * Log a nice warning if folks try to use View as Content and it's not supported * Add experimental flags for drag and drop tests * Fix crashes due to missing brush experimental flag * Make control templates from styles work alongside default templates * Catch up on which flags are still a concern * Fix infinite loop in platform tests * Attempt to fix occasionaly GroupableItemsViewController disposed crash * Make webview visible so we can verify it loaded in UI test screen shots * Fix merge Co-authored-by: Rui Marinho <[email protected]>
1 parent dacfe47 commit 2a97a6c

File tree

50 files changed

+1813
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1813
-674
lines changed

Stubs/Xamarin.Forms.Platform.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ internal class _ButtonRenderer { }
5454
[RenderWith(typeof(ImageButtonRenderer))]
5555
internal class _ImageButtonRenderer { }
5656

57+
#if !__IOS__
5758
[RenderWith(typeof(RadioButtonRenderer))]
5859
internal class _RadioButtonRenderer { }
60+
#endif
5961

6062
[RenderWith (typeof (TableViewRenderer))]
6163
internal class _TableViewRenderer { }

Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,9 @@
411411
</ItemGroup>
412412
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
413413
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
414+
<ProjectExtensions>
415+
<VisualStudio>
416+
<UserProperties XamarinHotReloadUnhandledDeviceExceptionXamarinFormsControlGalleryAndroidHideInfoBar="True" />
417+
</VisualStudio>
418+
</ProjectExtensions>
414419
</Project>

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10744.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55
using System.Text;
6+
using System.Threading.Tasks;
67
using Xamarin.Forms.CustomAttributes;
78
using Xamarin.Forms.Internals;
89

@@ -36,7 +37,10 @@ protected override void Init()
3637
_webView = new WebView()
3738
{
3839
Source = "https://dotnet.microsoft.com/apps/xamarin",
39-
Cookies = new System.Net.CookieContainer()
40+
Cookies = new System.Net.CookieContainer(),
41+
HorizontalOptions = LayoutOptions.Fill,
42+
VerticalOptions = LayoutOptions.Fill,
43+
HeightRequest = 600
4044
};
4145

4246
_webView.Navigating += (_, __) =>

Xamarin.Forms.Controls/App.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Reflection;
77
using System.Threading.Tasks;
8+
using Xamarin.Forms.Controls.GalleryPages.RadioButtonGalleries;
89
using Xamarin.Forms.Controls.Issues;
910
using Xamarin.Forms.Internals;
1011
using Xamarin.Forms.PlatformConfiguration;

Xamarin.Forms.Controls/CoreGalleryPages/CoreGalleryPage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ internal class CoreGalleryPage<T> : ContentPage
2121

2222
internal CoreGalleryPage()
2323
{
24+
Initialize();
25+
2426
Layout = new StackLayout
2527
{
2628
Padding = new Thickness(20)
@@ -55,6 +57,8 @@ internal CoreGalleryPage()
5557
}
5658
}
5759

60+
protected virtual void Initialize() { }
61+
5862
protected virtual void InitializeElement(T element) { }
5963

6064
protected virtual void Build(StackLayout stackLayout)

Xamarin.Forms.Controls/CoreGalleryPages/RadioButtonCoreGalleryPage.cs

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ class RadioButtonCoreGalleryPage : CoreGalleryPage<RadioButton>
99
protected override bool SupportsTapGestureRecognizer => true;
1010
protected override void InitializeElement(RadioButton element)
1111
{
12+
element.Content = "RadioButton";
13+
}
14+
15+
protected override void Initialize()
16+
{
17+
base.Initialize();
1218
Device.SetFlags(new List<string> { ExperimentalFlags.RadioButtonExperimental });
13-
element.Text = "RadioButton";
1419
}
1520

1621
protected override void OnDisappearing()
@@ -23,12 +28,12 @@ protected override void Build(StackLayout stackLayout)
2328
{
2429
base.Build(stackLayout);
2530

26-
IsEnabledStateViewContainer.View.Clicked += (sender, args) => IsEnabledStateViewContainer.TitleLabel.Text += " (Tapped)";
31+
IsEnabledStateViewContainer.View.CheckedChanged += (sender, args) => IsEnabledStateViewContainer.TitleLabel.Text += " (Checked Changed)";
2732

2833
var borderButtonContainer = new ViewContainer<RadioButton>(Test.Button.BorderColor,
2934
new RadioButton
3035
{
31-
Text = "BorderColor",
36+
Content = "BorderColor",
3237
BackgroundColor = Color.Transparent,
3338
BorderColor = Color.Red,
3439
BorderWidth = 1,
@@ -38,7 +43,7 @@ protected override void Build(StackLayout stackLayout)
3843
var borderRadiusContainer = new ViewContainer<RadioButton>(Test.Button.BorderRadius,
3944
new RadioButton
4045
{
41-
Text = "BorderRadius",
46+
Content = "BorderRadius",
4247
BackgroundColor = Color.Transparent,
4348
BorderColor = Color.Red,
4449
BorderWidth = 1,
@@ -48,101 +53,56 @@ protected override void Build(StackLayout stackLayout)
4853
var borderWidthContainer = new ViewContainer<RadioButton>(Test.Button.BorderWidth,
4954
new RadioButton
5055
{
51-
Text = "BorderWidth",
56+
Content = "BorderWidth",
5257
BackgroundColor = Color.Transparent,
5358
BorderColor = Color.Red,
5459
BorderWidth = 15,
5560
}
5661
);
5762

58-
var clickedContainer = new EventViewContainer<RadioButton>(Test.Button.Clicked,
59-
new RadioButton
60-
{
61-
Text = "Clicked"
62-
}
63-
);
64-
clickedContainer.View.Clicked += (sender, args) => clickedContainer.EventFired();
65-
66-
var pressedContainer = new EventViewContainer<RadioButton>(Test.Button.Pressed,
67-
new RadioButton
68-
{
69-
Text = "Pressed"
70-
}
71-
);
72-
pressedContainer.View.Pressed += (sender, args) => pressedContainer.EventFired();
73-
74-
var commandContainer = new ViewContainer<RadioButton>(Test.Button.Command,
75-
new RadioButton
76-
{
77-
Text = "Command",
78-
Command = new Command(() => DisplayActionSheet("Hello Command", "Cancel", "Destroy"))
79-
}
80-
);
81-
8263
var fontContainer = new ViewContainer<RadioButton>(Test.Button.Font,
8364
new RadioButton
8465
{
85-
Text = "Font",
86-
Font = Font.SystemFontOfSize(NamedSize.Large, FontAttributes.Bold)
66+
Content = "Font",
67+
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(RadioButton)),
68+
FontAttributes = FontAttributes.Bold
8769
}
8870
);
8971

9072
var textContainer = new ViewContainer<RadioButton>(Test.Button.Text,
9173
new RadioButton
9274
{
93-
Text = "Text"
75+
Content = "Text"
9476
}
9577
);
9678

9779
var textColorContainer = new ViewContainer<RadioButton>(Test.Button.TextColor,
9880
new RadioButton
9981
{
100-
Text = "TextColor",
82+
Content = "TextColor",
10183
TextColor = Color.Pink
10284
}
10385
);
10486

10587
var paddingContainer = new ViewContainer<RadioButton>(Test.Button.Padding,
10688
new RadioButton
10789
{
108-
Text = "Padding",
90+
Content = "Padding",
10991
BackgroundColor = Color.Red,
11092
Padding = new Thickness(20, 30, 60, 15)
11193
}
11294
);
11395

11496
var isCheckedContainer = new ValueViewContainer<RadioButton>(Test.RadioButton.IsChecked, new RadioButton() { IsChecked = true, HorizontalOptions = LayoutOptions.Start }, "IsChecked", value => value.ToString());
11597

116-
//var checkedVisualState = new VisualState { Name = "IsChecked" };
117-
//checkedVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_checked" });
118-
119-
//var group = new VisualStateGroup();
120-
//group.States.Add(checkedVisualState);
121-
122-
//var normalVisualState = new VisualState{ Name = "Normal" };
123-
//normalVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_unchecked" });
124-
//group.States.Add(normalVisualState);
125-
126-
//var groupList = new VisualStateGroupList();
127-
//groupList.Add(group);
128-
129-
//var rbStateManaged = new RadioButton() { HorizontalOptions = LayoutOptions.Start };
130-
//VisualStateManager.SetVisualStateGroups(rbStateManaged, groupList);
131-
132-
//var stateManagedContainer = new ValueViewContainer<RadioButton>(Test.RadioButton.ButtonSource, rbStateManaged, "IsChecked", value => value.ToString());
133-
13498
Add(borderButtonContainer);
13599
Add(borderRadiusContainer);
136100
Add(borderWidthContainer);
137-
Add(clickedContainer);
138-
Add(pressedContainer);
139-
Add(commandContainer);
140101
Add(fontContainer);
141102
Add(textContainer);
142103
Add(textColorContainer);
143104
Add(paddingContainer);
144105
Add(isCheckedContainer);
145-
//Add(stateManagedContainer);
146106
}
147107
}
148108
}

Xamarin.Forms.Controls/GalleryPages/PlatformTestsGallery/PlatformTestsConsole.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ await Device.InvokeOnMainThreadAsync(() => {
7171
protected override async void OnAppearing()
7272
{
7373
base.OnAppearing();
74-
74+
7575
if (_testsRunCount == 0)
7676
{
7777
await Run().ConfigureAwait(false);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d"
7+
x:Class="Xamarin.Forms.Controls.GalleryPages.RadioButtonGalleries.ContentProperties">
8+
9+
<ContentPage.Content>
10+
<StackLayout>
11+
<Label Text="Propagate standard Text properties to Content where applicable:"/>
12+
<Label FontSize="Small" Text="TextColor: Red, CharacterSpacing: 1.5, TextTransform: Lowercase, FontAttributes: Italic, FontSize: 14, FontFamily: BaskerVille"/>
13+
<RadioButton Content="Option A" GroupName="test"
14+
TextColor="Red"
15+
CharacterSpacing="1.5"
16+
TextTransform="Lowercase"
17+
FontAttributes="Italic"
18+
FontSize="14"
19+
FontFamily="Baskerville"
20+
/>
21+
<Label FontSize="Small" Text="TextColor: Blue, CharacterSpacing: 1, TextTransform: Uppercase, FontAttributes: Bold, FontSize: 18, FontFamily: Arial"/>
22+
<RadioButton Content="Option B" GroupName="test"
23+
TextColor="Blue"
24+
TextTransform="Uppercase"
25+
FontAttributes="Bold"
26+
FontSize="18"
27+
FontFamily="Arial"
28+
/>
29+
30+
<Label FontSize="Small" Text="The RadioButton below has its content set to Button (which makes little sense, but this is just an example). Anyway, the Text and Font properties are applied to the Button."/>
31+
32+
<RadioButton GroupName="test"
33+
TextColor="Green"
34+
TextTransform="Uppercase"
35+
FontAttributes="Bold"
36+
FontSize="12"
37+
FontFamily="Arial">
38+
39+
<RadioButton.Content>
40+
<Button Text="It's a button inside a button."></Button>
41+
</RadioButton.Content>
42+
43+
</RadioButton>
44+
45+
<Label FontSize="Small" Text="A Content View which already has these properties set/bound should ignore the RadioButton properties."/>
46+
47+
<RadioButton GroupName="test"
48+
TextColor="Green"
49+
TextTransform="Uppercase"
50+
FontAttributes="Bold"
51+
FontSize="12"
52+
FontFamily="Arial">
53+
54+
<RadioButton.Content>
55+
56+
<Label x:Name="MainLabel" Text="Properties already set."
57+
TextColor="Purple"
58+
TextTransform="Lowercase"
59+
FontSize="Micro"
60+
FontFamily="Baskerville"
61+
FontAttributes="Italic" />
62+
63+
64+
</RadioButton.Content>
65+
66+
</RadioButton>
67+
68+
<RadioButton GroupName="test"
69+
TextColor="Green"
70+
TextTransform="Uppercase"
71+
FontAttributes="Bold"
72+
FontSize="12"
73+
FontFamily="Arial">
74+
75+
<RadioButton.Content>
76+
<Label Text="Properties already bound"
77+
BindingContext="{x:Reference MainLabel}"
78+
TextColor="{Binding TextColor}"
79+
TextTransform="{Binding TextTransform}"
80+
FontSize="{Binding FontSize}"
81+
FontFamily="{Binding FontFamily}"
82+
FontAttributes="{Binding FontAttributes}" />
83+
</RadioButton.Content>
84+
85+
</RadioButton>
86+
</StackLayout>
87+
</ContentPage.Content>
88+
</ContentPage>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Xamarin.Forms.Xaml;
2+
3+
namespace Xamarin.Forms.Controls.GalleryPages.RadioButtonGalleries
4+
{
5+
[XamlCompilation(XamlCompilationOptions.Compile)]
6+
public partial class ContentProperties : ContentPage
7+
{
8+
public ContentProperties()
9+
{
10+
InitializeComponent();
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)