12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace InABox.Mobile
- {
- public class HideableToolbarItem : ToolbarItem
- {
- public HideableToolbarItem() : base()
- {
- this.InitVisibility();
- }
- private async void InitVisibility()
- {
- await Task.Delay(100);
- OnIsVisibleChanged(this, false, IsVisible);
- }
- //public ContentPage Parent { set; get; }
- public bool IsVisible
- {
- get { return (bool)GetValue(IsVisibleProperty); }
- set { SetValue(IsVisibleProperty, value); }
- }
- public static BindableProperty IsVisibleProperty =
- BindableProperty.Create<HideableToolbarItem, bool>(o => o.IsVisible, false, propertyChanged: OnIsVisibleChanged);
- private static void OnIsVisibleChanged(BindableObject bindable, bool oldvalue, bool newvalue)
- {
- var item = bindable as HideableToolbarItem;
- var parent = item.Parent as ContentPage;
- if (parent == null)
- return;
- var items = parent.ToolbarItems;
- if (newvalue && !items.Contains(item))
- {
- items.Add(item);
- }
- else if (!newvalue && items.Contains(item))
- {
- items.Remove(item);
- }
- }
- }
- }
|