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

RadioButton Implementation #8910

Merged
merged 10 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Stubs/Xamarin.Forms.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ internal class _ButtonRenderer { }
[RenderWith(typeof(ImageButtonRenderer))]
internal class _ImageButtonRenderer { }

#if __ANDROID__
[RenderWith(typeof(RadioButtonRenderer))]
#elif !TIZEN4_0
[RenderWith(typeof(RadioButtonRenderer))]
#endif
internal class _RadioButtonRenderer { }

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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@
<ItemGroup>
<LinkDescription Include="LinkDescription.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\rb_unchecked.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\rb_checked.png" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\googlemap.html" />
</ItemGroup>
Expand All @@ -408,4 +414,4 @@
</CreateItem>
<Copy SourceFiles="@(MapsKey)" DestinationFiles="Properties\MapsKey.cs" Condition="!Exists('Properties\MapsKey.cs')" />
</Target>
</Project>
</Project>
2 changes: 2 additions & 0 deletions Xamarin.Forms.Controls/CoreGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ public override string ToString()
new GalleryPageFactory(() => new EmbeddedFonts(), "Embedded Fonts"),
new GalleryPageFactory(() => new MemoryLeakGallery(), "Memory Leak"),
new GalleryPageFactory(() => new Issues.A11yTabIndex(), "Accessibility TabIndex"),
new GalleryPageFactory(() => new RadioButtonGroupGalleryPage(), "RadioButton group Gallery - Legacy"),
new GalleryPageFactory(() => new RadioButtonCoreGalleryPage(), "RadioButton Gallery"),
new GalleryPageFactory(() => new FontImageSourceGallery(), "Font ImageSource"),
new GalleryPageFactory(() => new IndicatorsSample(), "Indicator Gallery"),
new GalleryPageFactory(() => new CarouselViewGallery(), "CarouselView Gallery"),
Expand Down
140 changes: 140 additions & 0 deletions Xamarin.Forms.Controls/CoreGalleryPages/RadioButtonCoreGalleryPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls
{
class RadioButtonCoreGalleryPage : CoreGalleryPage<RadioButton>
{
protected override bool SupportsFocus => false;
protected override bool SupportsTapGestureRecognizer => true;
protected override void InitializeElement(RadioButton element)
{
element.Text = "RadioButton";
}

protected override void Build(StackLayout stackLayout)
{
base.Build(stackLayout);

IsEnabledStateViewContainer.View.Clicked += (sender, args) => IsEnabledStateViewContainer.TitleLabel.Text += " (Tapped)";

var borderButtonContainer = new ViewContainer<RadioButton>(Test.Button.BorderColor,
new RadioButton
{
Text = "BorderColor",
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
BorderWidth = 1,
}
);

var borderRadiusContainer = new ViewContainer<RadioButton>(Test.Button.BorderRadius,
Copy link
Member

@rmarinho rmarinho Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CornerRadius no ? but it also doesn't work for me if i change to something like:

	var borderRadiusContainer = new ViewContainer<RadioButton>(Test.Button.BorderRadius,
				new RadioButton
				{
					Text = "BorderRadius",
					BackgroundColor = Color.Transparent,
					BorderColor = Color.Red,
					BorderWidth = 1,
					CornerRadius = 5
				}
			);

new RadioButton
{
Text = "BorderRadius",
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
BorderWidth = 1,
}
);

var borderWidthContainer = new ViewContainer<RadioButton>(Test.Button.BorderWidth,
new RadioButton
{
Text = "BorderWidth",
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
BorderWidth = 15,
}
);

var clickedContainer = new EventViewContainer<RadioButton>(Test.Button.Clicked,
new RadioButton
{
Text = "Clicked"
}
);
clickedContainer.View.Clicked += (sender, args) => clickedContainer.EventFired();

var pressedContainer = new EventViewContainer<RadioButton>(Test.Button.Pressed,
new RadioButton
{
Text = "Pressed"
}
);
pressedContainer.View.Pressed += (sender, args) => pressedContainer.EventFired();

var commandContainer = new ViewContainer<RadioButton>(Test.Button.Command,
new RadioButton
{
Text = "Command",
Command = new Command(() => DisplayActionSheet("Hello Command", "Cancel", "Destroy"))
}
);

var fontContainer = new ViewContainer<RadioButton>(Test.Button.Font,
new RadioButton
{
Text = "Font",
Font = Font.SystemFontOfSize(NamedSize.Large, FontAttributes.Bold)
}
);

var textContainer = new ViewContainer<RadioButton>(Test.Button.Text,
new RadioButton
{
Text = "Text"
}
);

var textColorContainer = new ViewContainer<RadioButton>(Test.Button.TextColor,
new RadioButton
{
Text = "TextColor",
TextColor = Color.Pink
}
);

var paddingContainer = new ViewContainer<RadioButton>(Test.Button.Padding,
new RadioButton
{
Text = "Padding",
BackgroundColor = Color.Red,
Padding = new Thickness(20, 30, 60, 15)
}
);

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

var checkedVisualState = new VisualState { Name = "IsChecked" };
checkedVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_checked" });

var group = new VisualStateGroup();
group.States.Add(checkedVisualState);

var normalVisualState = new VisualState{ Name = "Normal" };
normalVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_unchecked" });
group.States.Add(normalVisualState);

var groupList = new VisualStateGroupList();
groupList.Add(group);

var rbStateManaged = new RadioButton() { HorizontalOptions = LayoutOptions.Start };
VisualStateManager.SetVisualStateGroups(rbStateManaged, groupList);

var stateManagedContainer = new ValueViewContainer<RadioButton>(Test.RadioButton.ButtonSource, rbStateManaged, "IsChecked", value => value.ToString());

Add(borderButtonContainer);
Add(borderRadiusContainer);
Add(borderWidthContainer);
Add(clickedContainer);
Add(pressedContainer);
Add(commandContainer);
Add(fontContainer);
Add(textContainer);
Add(textColorContainer);
Add(paddingContainer);
Add(isCheckedContainer);
Add(stateManagedContainer);
}
}
}
151 changes: 151 additions & 0 deletions Xamarin.Forms.Controls/GalleryPages/RadioButtonGroupGalleryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.GalleryPages.RadioButtonGroupGalleryPage">
<TabbedPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="NoGroupNameLVItemTemplate">
<ViewCell>
<RadioButton Text="RadioButton, Group=null"/>
</ViewCell>
</DataTemplate>
<DataTemplate x:Key="GroupNameLVItemTemplate">
<ViewCell>
<RadioButton GroupName="A" Text="RadioButton, Group='A'"/>
</ViewCell>
</DataTemplate>
<ControlTemplate x:Key="NoGroupNameControlTemplate">
<ContentPresenter />
</ControlTemplate>
<ControlTemplate x:Key="GroupNameControlTemplate">
<ContentPresenter />
</ControlTemplate>
</ResourceDictionary>
</TabbedPage.Resources>
<ContentPage Title="Parent level">
<ScrollView>
<StackLayout Padding="10">
<Label Text="Radio buttons with no group name are mutually exclusive at parent level"
Margin="0, 0, 0, 10"/>
<Label Text="StackLayout" />
<StackLayout>
<RadioButton Text="RadioButton, Group=null" />
<RadioButton Text="RadioButton, Group=null"/>
<RadioButton Text="RadioButton, Group=null"/>
</StackLayout>
<Label Text="StackLayout" Margin="0, 10"/>
<StackLayout>
<RadioButton Text="RadioButton, Group=null" />
<RadioButton Text="RadioButton, Group=null" />
<RadioButton Text="RadioButton, Group=null" />
</StackLayout>
<Label Text="ScrollView" />
<ScrollView>
<RadioButton Text="RadioButton, Group=null" />
</ScrollView>
<Label Text="ContentView" />
<ContentView>
<RadioButton Text="RadioButton, Group=null" />
</ContentView>
<Label Text="Frame" />
<Frame>
<RadioButton Text="RadioButton, Group=null" />
</Frame>
<Label Text="ContentView with ControlTemplate" />
<ContentView ControlTemplate="{StaticResource NoGroupNameControlTemplate}">
<RadioButton Text="RadioButton, Group=null" />
</ContentView>
<Label Text="ListView with ItemTemplate" />
<ListView ItemTemplate="{StaticResource NoGroupNameLVItemTemplate}"
VerticalOptions="Start"
HeightRequest="300">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
<x:String>monotouch</x:String>
</x:Array>
</ListView.ItemsSource>
</ListView>
</StackLayout>
</ScrollView>
</ContentPage>

<ContentPage Title="Page level">
<ScrollView>
<StackLayout Padding="10">
<Label Text="Radio buttons with same group name are mutually exclusive at page level"
Margin="0, 0, 0, 10"/>
<Label Text="StackLayout" />
<StackLayout>
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
<RadioButton GroupName="A" Text="RadioButton, Group='A'"/>
<RadioButton GroupName="A" Text="RadioButton, Group='A'"/>
</StackLayout>
<Label Text="StackLayout" Margin="0, 10"/>
<StackLayout>
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
</StackLayout>
<Label Text="ScrollView" />
<ScrollView>
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
</ScrollView>
<Label Text="ContentView" />
<ContentView>
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
</ContentView>
<Label Text="Frame" />
<Frame>
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
</Frame>
<Label Text="ContentView with ControlTemplate" />
<ContentView ControlTemplate="{StaticResource GroupNameControlTemplate}">
<RadioButton GroupName="A" Text="RadioButton, Group='A'" />
</ContentView>
<Label Text="ListView with ItemTemplate" />
<ListView ItemTemplate="{StaticResource GroupNameLVItemTemplate}"
VerticalOptions="Start"
HeightRequest="300">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
<x:String>monotouch</x:String>
</x:Array>
</ListView.ItemsSource>
</ListView>
</StackLayout>
</ScrollView>
</ContentPage>

<ContentPage Title="Test">
<ScrollView>
<StackLayout Padding="10">
<Label Text="Test with radio buttons with no group name or same group name"
Margin="0, 0, 0, 10"/>
<Label Text="StackLayout" />
<StackLayout>
<RadioButton GroupName="A" Text="RadioButton, GroupName='A'" />
<RadioButton GroupName="A" Text="RadioButton, GroupName='A'" />
<RadioButton Text="RadioButton, GroupName=null" />
</StackLayout>
<StackLayout Margin="0, 10">
<RadioButton GroupName="A" Text="RadioButton, GroupName='A'" />
<RadioButton GroupName="B" Text="RadioButton, GroupName='B'" />
<RadioButton GroupName="B" Text="RadioButton, GroupName='B'" />
<RadioButton Text="RadioButton, GroupName=null" />
</StackLayout>
<StackLayout>
<RadioButton GroupName="A" Text="RadioButton, GroupName='A'" />
<RadioButton GroupName="B" Text="RadioButton, GroupName='B'" />
<RadioButton GroupName="C" Text="RadioButton, GroupName='C'" />
<RadioButton GroupName="C" Text="RadioButton, GroupName='C'" />
<RadioButton Text="RadioButton, GroupName=null" />
<RadioButton Text="RadioButton, GroupName=null" />
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>
</TabbedPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Xamarin.Forms.Xaml;

namespace Xamarin.Forms.Controls.GalleryPages
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class RadioButtonGroupGalleryPage : TabbedPage
{
public RadioButtonGroupGalleryPage()
{
InitializeComponent();
}
}
}
5 changes: 5 additions & 0 deletions Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<Generator></Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="GalleryPages\RadioButtonGroupGalleryPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="Fonts\" />
Expand Down
Loading