に処理する方法がここに誰のためのUWPのためのソリューションがあるcardviewのイベントをクリック扱うに役立つかもしれません興味がある!
[assembly: ExportRenderer(typeof(RoundedButton), typeof(RoundedButtonRenderer))]
namespace Platformspecific.Buttons
{
public class RoundedButtonRenderer : ViewRenderer<RoundedButton, Windows.UI.Xaml.Shapes.Rectangle>
{
Xamarin.Forms.Color originalBackground;
private RoundedButton _control;
protected override void OnElementChanged(ElementChangedEventArgs<RoundedButton> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
_control = e.NewElement as RoundedButton;
originalBackground = _control.CustomBackgroundColor;
this.PointerPressed += Control_Pressed;
this.PointerReleased += Control_Released;
this.PointerExited += Control_Released;
var rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
rectangle.Width = this.Width; // 100;
rectangle.Height = this.Height;
rectangle.Fill = new SolidColorBrush(ToMediaColor(_control.CustomBackgroundColor));
rectangle.RadiusX = _control.BorderRadius;
rectangle.RadiusY = _control.BorderRadius;
rectangle.Stroke = new SolidColorBrush(ToMediaColor(_control.OutlineColor));
rectangle.StrokeThickness = _control.BorderWidth;
this.SetNativeControl(rectangle);
}
}
public static Windows.UI.Color ToMediaColor(Xamarin.Forms.Color color)
{
return Windows.UI.Color.FromArgb(((byte)(color.A * 255)), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255));
}
void Control_Pressed(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Xaml.Shapes.Rectangle _rectangle = e.OriginalSource as Windows.UI.Xaml.Shapes.Rectangle;
var rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
rectangle.Width = this.Width;
rectangle.Height = this.Height;
rectangle.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 100, 100, 100));
rectangle.RadiusX = _control.BorderRadius;
rectangle.RadiusY = _control.BorderRadius;
rectangle.Stroke = new SolidColorBrush(ToMediaColor(_control.OutlineColor));
rectangle.StrokeThickness = _control.BorderWidth;
this.SetNativeControl(rectangle);
e.Handled = false;
}
void Control_Released(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Xaml.Shapes.Rectangle _rectangle = e.OriginalSource as Windows.UI.Xaml.Shapes.Rectangle;
var rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
rectangle.Width = this.Width;
rectangle.Height = this.Height;
rectangle.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(((byte)(originalBackground.A * 255)), (byte)(originalBackground.R * 255), (byte)(originalBackground.G * 255), (byte)(originalBackground.B * 255)));
rectangle.RadiusX = _control.BorderRadius;
rectangle.RadiusY = _control.BorderRadius;
rectangle.Stroke = new SolidColorBrush(ToMediaColor(_control.OutlineColor));
rectangle.StrokeThickness = _control.BorderWidth;
rectangle.Fill = new SolidColorBrush(ToMediaColor(_control.CustomBackgroundColor));
rectangle.Stroke = new SolidColorBrush(ToMediaColor(_control.CustomBackgroundColor));
this.SetNativeControl(rectangle);
e.Handled = false;
}
}
}
(http://meta.stackoverflow.com/questions/318249/handling-ops-pre-emptive-defensive-instructions)[これをチェック] –
@MD何?私の質問でどこの条件を満たしていますか? –
@ JoakimMおそらくここに「Frame/ContentView/Button用のカスタムレンダラーを使ってこれを作成するのを助けても気にしない」 – Sreeraj