This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
RadioButton Implementation #8910
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7dbcb8b
RadioButton
andreinitescu e102b4e
Removed unused files
andreinitescu 699a457
Rebase and make it run
jfversluis 2f7fd76
First round of feedback
jfversluis c223c1e
Revert AppCompatButton -> AButton
jfversluis 029c374
Cleaned minor usings
jfversluis 40d4879
Fix unselecting radiobutton on iOS
jfversluis 53120fd
Fixed Mac OS grouping
jfversluis 40ce7e7
Merge branch 'master' into radiobutton
rmarinho d0b4c8c
[Android] Fix API29 usages
rmarinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.76 KB
Xamarin.Forms.ControlGallery.Android/Resources/drawable/rb_checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.91 KB
Xamarin.Forms.ControlGallery.Android/Resources/drawable/rb_unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Xamarin.Forms.Controls/CoreGalleryPages/RadioButtonCoreGalleryPage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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
151
Xamarin.Forms.Controls/GalleryPages/RadioButtonGroupGalleryPage.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
13 changes: 13 additions & 0 deletions
13
Xamarin.Forms.Controls/GalleryPages/RadioButtonGroupGalleryPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: