summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.UAP/FormsCommandBar.cs
blob: 2ca665af65fc35eb4278673c53f5ef3d951e3cb3 (plain)
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
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Xamarin.Forms.Platform.UWP
{
	public class FormsCommandBar : CommandBar
	{
		Windows.UI.Xaml.Controls.Button _moreButton;

		public FormsCommandBar()
		{
			PrimaryCommands.VectorChanged += OnCommandsChanged;
			SecondaryCommands.VectorChanged += OnCommandsChanged;
		}

		protected override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			_moreButton = GetTemplateChild("MoreButton") as Windows.UI.Xaml.Controls.Button;
			UpdateMore();
		}

		void OnCommandsChanged(IObservableVector<ICommandBarElement> sender, IVectorChangedEventArgs args)
		{
			UpdateMore();
		}

		void UpdateMore()
		{
			if (_moreButton == null)
				return;

			_moreButton.Visibility = PrimaryCommands.Count > 0 || SecondaryCommands.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
		}
	}
}