forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormsCancelButton.cs
52 lines (42 loc) · 1.37 KB
/
FormsCancelButton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Xamarin.Forms.Platform.UWP
{
internal class FormsCancelButton : Windows.UI.Xaml.Controls.Button
{
TextBlock _cancelButtonGlyph;
Border _cancelButtonBackground;
public Brush ForegroundBrush
{
get => _cancelButtonGlyph.Foreground;
set => _cancelButtonGlyph.Foreground = value;
}
public Brush BackgroundBrush
{
get => _cancelButtonBackground.Background;
set => _cancelButtonBackground.Background = value;
}
public bool IsReady { get; private set; }
public event EventHandler ReadyChanged;
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
_cancelButtonGlyph = (TextBlock)GetTemplateChild("GlyphElement");
_cancelButtonBackground = (Border)GetTemplateChild("BorderElement");
if (_cancelButtonGlyph != null && _cancelButtonBackground != null)
{
// The SearchBarRenderer needs to be able to check whether we're ready to have the colors set
// (we won't be until the first time the button actually appears, which requires the search bar
// to be focused and have text in it)
IsReady = true;
// And we need to inform the SearchBarRenderer of this so it can run the button color update method
OnReadyChanged();
}
}
protected virtual void OnReadyChanged()
{
ReadyChanged?.Invoke(this, EventArgs.Empty);
}
}
}