コード例 #1
0
        private SegmentItem GetSegmentItem(object data)
        {
            SegmentItem item = null;

            if (data is SegmentItem)
            {
                item = (SegmentItem)data;
            }
            else
            {
                item = new SegmentItem();
                var view = (View)this.ItemTemplate.CreateContent();
                if (view is SegmentItem)
                {
                    item = (SegmentItem)view;
                }
                else
                {
                    item.Content = view;
                }
                item.BindingContext = data;
            }

            item.HorizontalOptions = LayoutOptions.FillAndExpand;
            item.VerticalOptions   = LayoutOptions.FillAndExpand;

            item.Content.HorizontalOptions = LayoutOptions.Center;
            item.Content.VerticalOptions   = LayoutOptions.Center;

            TapBinder.SetCmd(item, this.SelectedCmd);
            TapBinder.SetParam(item, item);

            return(item);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="idx"></param>
        /// <returns></returns>
        private View GetChild(object data)
        {
            View child = null;

            if (this.ItemTemplate != null || this.ItemTemplateSelector != null)
            {
                if (this.ItemTemplateSelector != null)
                {
                    child = (View)this.ItemTemplateSelector.SelectTemplate(data, this).CreateContent();
                }
                else if (this.ItemTemplate != null)
                {
                    child = (View)this.ItemTemplate.CreateContent();
                }

                if (child != null)
                {
                    child.BindingContext = data;
                }
            }
            if (child == null)
            {
                child = new Label()
                {
                    Text = "Not set ItemTemplate"
                }
            }
            ;

            child.BindingContext = data;
            child.SetBinding(TapBinder.CmdProperty, new Binding(nameof(this.ItemTapedCmd), source: this));
            TapBinder.SetParam(child, data);
            TapBinder.SetWithFeedback(child, ItemWithFeedBack);
            return(child);
        }
コード例 #3
0
        private static void ItemWithFeedBackPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var grid = (UniformGrid)bindable;

            foreach (var view in grid.Children)
            {
                TapBinder.SetWithFeedback(view, (bool)newValue);
            }
        }
コード例 #4
0
ファイル: CheckBox.cs プロジェクト: yz1311/XFControls
        //public static ImageSource DefaultCheckedImg1 {
        //    get {
        //        return DefaultCheckedImg;
        //    }
        //}

        public CheckBox()
        {
            this.TapCmd = new Command(() => {
                this.Checked = !this.Checked;

                if (this.CheckChanged != null)
                {
                    this.CheckChanged.Invoke(this, new EventArgs());
                }

                if (this.CheckChangedCmd != null && this.CheckChangedCmd.CanExecute(this.Checked))
                {
                    this.CheckChangedCmd.Execute(this.Checked);
                }
            });

            var cols = new ColumnDefinitionCollection();

            cols.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            cols.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            this.Grid = new Grid()
            {
                ColumnDefinitions = cols,
            };

            //绑定内部Tap 命令
            TapBinder.SetCmd(this.Grid, this.TapCmd);

            this.Content = this.Grid;

            this.Label = new Label()
            {
                BindingContext        = this,
                VerticalTextAlignment = TextAlignment.Center
            };
            this.Label.SetBinding(Label.TextProperty, "Text");
            this.Label.SetBinding(Label.IsVisibleProperty, "ShowLabel");
            this.Label.SetValue(Grid.ColumnProperty, 1);

            this.Grid.Children.Add(this.Label);

            this.Icon = new Image()
            {
                WidthRequest  = this.Size,
                HeightRequest = this.Size,
                Source        = this.OffImg
            };
            this.Icon.SetValue(Grid.ColumnProperty, 0);
            this.Grid.Children.Add(this.Icon);
        }
コード例 #5
0
        private static void ItemTapedCmdChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var g    = (UniformGrid)bindable;
            var flag = (newValue != null || g.ItemTapedCmd != null);

            foreach (var v in g.Children)
            {
                TapBinder.SetWithFeedback(v, flag);
            }
        }
コード例 #6
0
        private static void ItemTapedCmdChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var repeater = (Repeater)bindable;
            var flag     = (newValue != null || repeater.ItemTapedCmd != null);

            foreach (var v in repeater.Container.Children)
            {
                TapBinder.SetWithFeedback(v, flag);
            }
        }
コード例 #7
0
        /// <summary>
        /// 从模板/模板选择器创建子视图
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private View GetChildView(object data)
        {
            View view = null;

            if (this.ItemTemplate != null || this.ItemTemplateSelector != null)
            {
                if (this.ItemTemplateSelector != null)
                {
                    // SelectTemplate 的第二个参数,即 TemplateSelector 的 OnSelectTemplate 方法的 container 参数
                    view = (View)this.ItemTemplateSelector.SelectTemplate(data, this).CreateContent();
                }
                else if (this.ItemTemplate != null)
                {
                    view = (View)this.ItemTemplate.CreateContent();
                }

                if (view != null)
                {
                    view.BindingContext = data;
                    TapBinder.SetCmd(view, this.TapCmd);
                    TapBinder.SetParam(view, data);
                    if (this.ItemTaped == null && this.ItemTapedCmd == null)
                    {
                        TapBinder.SetWithFeedback(view, false);
                    }
                }
            }

            if (view == null)
            {
                view = new Label()
                {
                    Text = "111"
                }
            }
            ;

            return(view);
        }
コード例 #8
0
ファイル: TabbedView.cs プロジェクト: yz1311/XFControls
        /// <summary>
        /// 从模板/模板选择器创建标签
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private View GetTabView(object data)
        {
            View view = null;

            if (this.TabTemplate != null || this.TabTemplateSelector != null)
            {
                //优先使用 TemplateSelector
                if (this.TabTemplateSelector != null)
                {
                    // SelectTemplate 的第二个参数,即 TemplateSelector 的 OnSelectTemplate 方法的 container 参数
                    view = (View)this.TabTemplateSelector.SelectTemplate(data, this).CreateContent();
                }
                else if (this.TabTemplate != null)
                {
                    view = (View)this.TabTemplate.CreateContent();
                }

                if (view != null)
                {
                    //上下文
                    view.BindingContext = data;
                }
            }

            if (view == null)
            {
                view = new Label()
                {
                    Text = "Tab"
                }
            }
            ;

            TapBinder.SetCmd(view, this.SelectedCmd);
            TapBinder.SetParam(view, data);

            return(view);
        }
    }
コード例 #9
0
        protected virtual Radio GetRadio(object data)
        {
            Radio item = null;

            if (data is Radio)
            {
                item = (Radio)data;
            }
            else
            {
                item       = new Radio();
                item.Value = data;

                if (!string.IsNullOrWhiteSpace(this.DisplayPath))
                {
                    //item.Text = Helper.GetProperty<string>(data, this.DisplayPath, "DisplayPath Invalid");
                    //item.SetBinding(Radio.TextProperty, this.DisplayPath);
                    item.SetBinding(Radio.TextProperty, new Binding(this.DisplayPath, source: data));
                }
                else
                {
                    item.Text = data.ToString();
                }
            }

            item.Size = this.RadioSize;

            if (this.UnSelectedItemControlTemplate != null)
            {
                item.ControlTemplate = this.UnSelectedItemControlTemplate;
            }

            TapBinder.SetCmd(item, this.SelectedCmd);
            TapBinder.SetParam(item, item);

            return(item);
        }
コード例 #10
0
        public Stepper()
        {
            InitializeComponent();

            this.Resources = new ResourceDictionary();
            this.Resources.Add("BorderColor", this.BorderColor);
            this.Resources.Add("TextColor", this.TextColor);

            TapBinder.SetCmd(this.btnIncrease, new Command(() => {
                //if (this.btnIncrease.IsEnabled) {
                this.Value += this.Step;
                this.Update();
                //}
            }));

            TapBinder.SetCmd(this.btnReduce, new Command(() => {
                //if (this.btnReduce.IsEnabled) {
                this.Value -= this.Step;
                this.Update();
                //}
            }));

            this.Update();
        }
コード例 #11
0
ファイル: FontIcon.cs プロジェクト: yz1311/XFControls
 private static void TapCmdChanged(BindableObject bindable, object oldValue, object newValue)
 {
     TapBinder.SetCmd(bindable, (ICommand)newValue);
 }
コード例 #12
0
ファイル: FontIcon.cs プロジェクト: yz1311/XFControls
 private static void TapCmdParamChanged(BindableObject bindable, object oldValue, object newValue)
 {
     TapBinder.SetParam(bindable, newValue);
 }
コード例 #13
0
ファイル: Radio.cs プロジェクト: songyandong/XFControls
 internal void SetTap(ICommand cmd)
 {
     TapBinder.SetCmd(this.Content, cmd);
     TapBinder.SetParam(this.Content, this);
 }
コード例 #14
0
ファイル: TabView.cs プロジェクト: eustachywieczorek/RRR
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="idx"></param>
        /// <returns></returns>
        private TabPageView GetTab(object data, int idx)
        {
            TabPageView item;

            if (data is TabPageView)
            {
                item = (TabPageView)data;
            }
            else
            {
                item = new TabPageView()
                {
                    Index          = idx,
                    BindingContext = data
                };

                #region headView
                View headView = null;

                if (this.TabTemplate != null || this.TabTemplateSelector != null)
                {
                    //优先使用 TemplateSelector
                    if (this.TabTemplateSelector != null)
                    {
                        // SelectTemplate 的第二个参数,即 TemplateSelector 的 OnSelectTemplate 方法的 container 参数
                        headView = (View)this.TabTemplateSelector.SelectTemplate(data, item).CreateContent();
                    }
                    else if (this.TabTemplate != null)
                    {
                        headView = (View)this.TabTemplate.CreateContent();
                    }

                    if (headView != null)
                    {
                        //上下文
                        headView.BindingContext = data;
                    }
                }

                if (headView == null)
                {
                    headView = new Label()
                    {
                        Text = "Tab"
                    }
                }
                ;


                //item.Header = headView;
                item.Header = new ContentView()
                {
                    Content        = headView,
                    BindingContext = item
                };

                //添加手势
                TapBinder.SetCmd(headView, this.TabSelectedCmd);
                TapBinder.SetParam(headView, item);
                #endregion

                #region bodyView
                View bodyView = null;
                if (this.ItemTemplate != null || this.ItemTemplateSelector != null)
                {
                    if (this.ItemTemplateSelector != null)
                    {
                        bodyView = (View)this.ItemTemplateSelector.SelectTemplate(data, item).CreateContent();
                    }
                    else if (this.ItemTemplate != null)
                    {
                        bodyView = (View)this.ItemTemplate.CreateContent();
                    }

                    if (bodyView != null)
                    {
                        bodyView.BindingContext = data;
                    }
                }
                if (bodyView == null)
                {
                    bodyView = new Label()
                    {
                        Text = "Body"
                    }
                }
                ;

                item.Content = bodyView;
                #endregion
            }


            item.Header.SetBinding(ContentView.ControlTemplateProperty, new Binding(nameof(this.TabControlTemplate), source: this));
            item.Header.SetBinding(View.WidthRequestProperty, new Binding("TabWidthRequest", source: this));
            item.Header.SetBinding(View.HeightRequestProperty, new Binding("TabHeightRequest", source: this));

            item.SetBinding(TabPageView.TabPositionProperty, new Binding(nameof(TabPosition), source: this));

            this.SetTransition(item);

            return(item);
        }