Merge pull request #45 from xamarin/fix-bugzilla25662

[A] SwitchCell IsEnabled bit now affects the toggle
This commit is contained in:
Samantha Houts 2016-04-07 05:30:13 -07:00 коммит произвёл Rui Marinho
Родитель c98d338e15
Коммит bb7bf53447
2 изменённых файлов: 33 добавлений и 10 удалений

Просмотреть файл

@ -1,24 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.CustomAttributes;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 25662, "Setting IsEnabled does not disable SwitchCell")]
public class Bugzilla25662 : ContentPage
public class Bugzilla25662 : TestContentPage
{
[Preserve(AllMembers = true)]
class MySwitch : SwitchCell
{
public MySwitch ()
{
IsEnabled = false;
SetBinding(SwitchCell.TextProperty, new Binding("."));
OnChanged += (sender, e) => Text = "FAIL";
}
}
public Bugzilla25662 ()
protected override void Init ()
{
var list = new ListView {
ItemsSource = new[] {
@ -28,8 +32,16 @@ namespace Xamarin.Forms.Controls.Issues
};
Content = list;
Title = "My page";
}
}
#if UITEST
[Test]
public void Bugzilla25662Test ()
{
RunningApp.WaitForElement (q => q.Marked ("One"));
RunningApp.Tap(q => q.Marked("One"));
RunningApp.WaitForNoElement(q => q.Marked("FAIL"));
}
#endif
}
}

Просмотреть файл

@ -23,6 +23,7 @@ namespace Xamarin.Forms.Platform.Android
UpdateText();
UpdateChecked();
UpdateHeight();
UpdateIsEnabled(_view, cell);
return _view;
}
@ -35,6 +36,8 @@ namespace Xamarin.Forms.Platform.Android
UpdateChecked();
else if (args.PropertyName == "RenderHeight")
UpdateHeight();
else if (args.PropertyName == Cell.IsEnabledProperty.PropertyName)
UpdateIsEnabled(_view, (SwitchCell)sender);
}
void UpdateChecked()
@ -42,6 +45,14 @@ namespace Xamarin.Forms.Platform.Android
((ASwitch)_view.AccessoryView).Checked = ((SwitchCell)Cell).On;
}
void UpdateIsEnabled(SwitchCellView cell, SwitchCell switchCell)
{
cell.Enabled = switchCell.IsEnabled;
var aSwitch = cell.AccessoryView as ASwitch;
if (aSwitch != null)
aSwitch.Enabled = switchCell.IsEnabled;
}
void UpdateHeight()
{
_view.SetRenderHeight(Cell.RenderHeight);