Ejemplo n.º 1
0
 public PropertyItemViewModel(PropertyItemViewModel p)
 {
     ItemSource     = p.ItemSource;
     Parent         = p.Parent;
     _property      = p._property.Clone() as PropertyDef;
     _property.Name = Utils.GetUniqueName(p.Name, ItemSource.Select(x => (x as PropertyItemViewModel).Name));
 }
Ejemplo n.º 2
0
 public SoundItemViewModel() // new item
 {
     _sound = new GameSound
     {
         Name   = Utils.GetUniqueName("Sound", ItemSource.Select(x => (x as SoundItemViewModel).Name)),
         Gameid = ViewModelLocator.GameLoader.Game.Id,
         //Src = ViewModelLocator.GameLoader.GamePath
         Src = AssetManager.Instance.Assets.FirstOrDefault(x => x.Type == AssetType.Sound)?.FullPath,
     };
 }
Ejemplo n.º 3
0
 public SymbolItemViewModel() // new item
 {
     _symbol = new Symbol
     {
         Id   = Utils.GetUniqueName("Symbol", ItemSource.Select(x => (x as SymbolItemViewModel).Id)),
         Name = "Symbol",
         //Source = ViewModelLocator.GameLoader.GamePath
         Source = AssetManager.Instance.Assets.FirstOrDefault(x => x.Type == AssetType.Image)?.FullPath,
     };
 }
Ejemplo n.º 4
0
 public SymbolItemViewModel(SymbolItemViewModel s) // copy item
 {
     _symbol = new Symbol()
     {
         Id     = Utils.GetUniqueName(s.Id, ItemSource.Select(x => (x as SymbolItemViewModel).Name)),
         Name   = s.Name,
         Source = s.Asset.FullPath
     };
     Parent     = s.Parent;
     ItemSource = s.ItemSource;
 }
Ejemplo n.º 5
0
        public override void Insert()
        {
            if (CanInsert == false)
            {
                return;
            }
            var index = ItemSource.IndexOf(this);

            ItemSource.Insert(index, new BoardItemViewModel()
            {
                ItemSource = ItemSource,
                Parent     = Parent,
                Name       = Utils.GetUniqueName("New Board", ItemSource.Select(x => (x as BoardItemViewModel).Name))
            });
        }
Ejemplo n.º 6
0
        private void AddTabToView(TabItem tab)
        {
            var tabSize = (TabSizeOption.IsAbsolute && TabSizeOption.Value.Equals(0)) ? new GridLength(1, GridUnitType.Star) : TabSizeOption;

            _headerContainerGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = tabSize
            });

            tab.IsCurrent = _headerContainerGrid.ColumnDefinitions.Count - 1 == SelectedTabIndex;

            var headerIcon = new Image
            {
                Margin            = new Thickness(0, 8, 0, 0),
                BindingContext    = tab,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                WidthRequest      = tab.HeaderIconSize,
                HeightRequest     = tab.HeaderIconSize
            };

            headerIcon.SetBinding(Image.SourceProperty, nameof(TabItem.HeaderIcon));
            headerIcon.SetBinding(IsVisibleProperty, nameof(TabItem.HeaderIcon), converter: new NullToBoolConverter());

            var headerLabel = new Label
            {
                BindingContext          = tab,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center,
                HorizontalOptions       = LayoutOptions.Center,
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                Margin = new Thickness(5, 8, 5, 5)
            };

            headerLabel.SetBinding(Label.TextProperty, nameof(TabItem.HeaderText));
            headerLabel.SetBinding(Label.TextColorProperty, nameof(TabItem.HeaderTextColor));
            headerLabel.SetBinding(Label.FontSizeProperty, nameof(TabItem.HeaderTabTextFontSize));
            headerLabel.SetBinding(Label.FontFamilyProperty, nameof(TabItem.HeaderTabTextFontFamily));
            headerLabel.SetBinding(Label.FontAttributesProperty, nameof(TabItem.HeaderTabTextFontAttributes));
            headerLabel.SetBinding(IsVisibleProperty, nameof(TabItem.HeaderText), converter: new NullToBoolConverter());

            var selectionBarBoxView = new BoxView
            {
                VerticalOptions = LayoutOptions.End,
                BindingContext  = tab,
                HeightRequest   = HeaderSelectionUnderlineThickness,
                WidthRequest    = HeaderSelectionUnderlineWidth
            };
            //selectionBarBoxView.SetBinding(IsVisibleProperty, nameof(TabItem.IsCurrent));
            var underlineColorBinding = new Binding(nameof(TabItem.IsCurrent), BindingMode.OneWay, new SelectedTabHeaderToTabBackgroundColorConverter(), this);

            //selectionBarBoxView.SetBinding(BoxView.ColorProperty, nameof(TabItem.HeaderSelectionUnderlineColor), BindingMode.OneWay, new SelectedTabHeaderToTabBackgroundColorConverter(), );
            selectionBarBoxView.SetBinding(BoxView.BackgroundColorProperty, underlineColorBinding);

            selectionBarBoxView.SetBinding(WidthRequestProperty, nameof(TabItem.HeaderSelectionUnderlineWidth));
            selectionBarBoxView.SetBinding(HeightRequestProperty, nameof(TabItem.HeaderSelectionUnderlineThickness));
            selectionBarBoxView.SetBinding(HorizontalOptionsProperty,
                                           nameof(TabItem.HeaderSelectionUnderlineWidth),
                                           converter: new DoubleToLayoutOptionsConverter());

            selectionBarBoxView.PropertyChanged += (object sender, PropertyChangedEventArgs e) =>
            {
                if (e.PropertyName == nameof(TabItem.IsCurrent))
                {
                    SetPosition(ItemSource.IndexOf((TabItem)((BoxView)sender).BindingContext));
                }
                if (e.PropertyName == nameof(WidthRequest))
                {
                    selectionBarBoxView.HorizontalOptions = tab.HeaderSelectionUnderlineWidth > 0 ? LayoutOptions.CenterAndExpand : LayoutOptions.FillAndExpand;
                }
            };

            View headerItemView;

            if (TabHeaderItemTemplate != null)
            {
                headerItemView = (View)TabHeaderItemTemplate.CreateContent();
                headerItemView.BindingContext = tab;
            }
            else
            {
                headerItemView = new StackLayout
                {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Children        = { headerIcon, headerLabel, selectionBarBoxView },
                    BackgroundColor = HeaderBackgroundColor
                };
            }

            var tapRecognizer = new TapGestureRecognizer();

            tapRecognizer.Tapped += (object s, EventArgs e) =>
            {
                _supressCarouselViewPositionChangedEvent = true;
                var capturedIndex = _headerContainerGrid.Children.IndexOf((View)s);
                SetPosition(capturedIndex);
                _supressCarouselViewPositionChangedEvent = false;
            };
            headerItemView.GestureRecognizers.Add(tapRecognizer);
            _headerContainerGrid.Children.Add(headerItemView, _headerContainerGrid.ColumnDefinitions.Count - 1, 0);
            _carouselView.ItemsSource = ItemSource.Select(t => t.Content);
        }