当前位置: 首页>>代码示例>>C#>>正文


C# ContextMenu.SetBinding方法代码示例

本文整理汇总了C#中System.Windows.Controls.ContextMenu.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.SetBinding方法的具体用法?C# ContextMenu.SetBinding怎么用?C# ContextMenu.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.ContextMenu的用法示例。


在下文中一共展示了ContextMenu.SetBinding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnApplyTemplate

 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.toggleButton = (base.Template.FindName("PART_DropDown", this) as ToggleButton);
     if (this.toggleButton != null)
     {
         ContextMenu contextMenu = new ContextMenu
         {
             PlacementTarget = this.toggleButton,
             Placement = PlacementMode.Bottom,
             Style = base.FindResource("DefaultContextMenuStyle") as Style
         };
         Binding b = new Binding
         {
             Source = this.toggleButton,
             Mode = BindingMode.TwoWay,
             Path = new PropertyPath(ToggleButton.IsCheckedProperty)
         };
         contextMenu.SetBinding(ContextMenu.IsOpenProperty, b);
         this.toggleButton.ContextMenu = contextMenu;
         this.toggleButton.Checked += new RoutedEventHandler(this.DropDownButton_Checked);
     }
 }
开发者ID:super860327,项目名称:firstwpftest,代码行数:23,代码来源:DropDownTabControl.cs

示例2: OnApplyTemplate

        /*
         * Protected override methods
         * 
        */

        #region Overrides

        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // set up the event handler for the template parts
            _toggleButton = this.Template.FindName("PART_DropDown", this) as ToggleButton;
            if (_toggleButton != null)
            {
                // create a context menu for the togglebutton
                ContextMenu cm = new ContextMenu { PlacementTarget = _toggleButton, Placement = PlacementMode.Bottom };

                // create a binding between the togglebutton's IsChecked Property
                // and the Context Menu's IsOpen Property
                Binding b = new Binding
                {
                    Source = _toggleButton,
                    Mode = BindingMode.TwoWay,
                    Path = new PropertyPath(ToggleButton.IsCheckedProperty)
                };

                cm.SetBinding(ContextMenu.IsOpenProperty, b);

                _toggleButton.ContextMenu = cm;
                _toggleButton.Checked += DropdownButton_Checked;
            }

            ScrollViewer scrollViewer = this.Template.FindName("PART_ScrollViewer", this) as ScrollViewer;

            // set up event handlers for the RepeatButtons Click event
            RepeatButton repeatLeft = this.Template.FindName("PART_RepeatLeft", this) as RepeatButton;
            if (repeatLeft != null)
            {
                repeatLeft.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineLeft();
                };
            }

            RepeatButton repeatRight = this.Template.FindName("PART_RepeatRight", this) as RepeatButton;
            if (repeatRight != null)
            {
                repeatRight.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineRight();
                };
            }

            // set up the event handler for the 'New Tab' Button Click event
            _addNewButton = this.Template.FindName("PART_NewTabButton", this) as ButtonBase;
            if (_addNewButton != null)
                _addNewButton.Click += ((sender, routedEventArgs) => AddTabItem());
        }
开发者ID:Kayomani,项目名称:FAP,代码行数:64,代码来源:TabControl.cs

示例3: OnApplyTemplate

        /*
         * Protected override methods
         * 
        */

        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            try
            {
                base.OnApplyTemplate();
                this.AllowDrop = true;
                _RowDefinition0 = this.Template.FindName("RowDefinition0", this) as RowDefinition;
                // set up the event handler for the template parts
                _toggleButton = this.Template.FindName("PART_DropDown", this) as ToggleButton;
                if (_toggleButton != null)
                {
                    // create a context menu for the togglebutton
                    ContextMenu cm = new ContextMenu();
                    cm.PlacementTarget = _toggleButton;
                    cm.Placement = PlacementMode.Bottom;

                    // create a binding between the togglebutton's IsChecked Property
                    // and the Context Menu's IsOpen Property
                    Binding b = new Binding();
                    b.Source = _toggleButton;
                    b.Mode = BindingMode.TwoWay;
                    b.Path = new PropertyPath(ToggleButton.IsCheckedProperty);

                    cm.SetBinding(ContextMenu.IsOpenProperty, b);

                    _toggleButton.ContextMenu = cm;
                    _toggleButton.Checked += DropdownButton_Checked;
                }

                ScrollViewer scrollViewer = this.Template.FindName("PART_ScrollViewer", this) as ScrollViewer;

                // set up event handlers for the RepeatButtons Click event
                RepeatButton repeatLeft = this.Template.FindName("PART_RepeatLeft", this) as RepeatButton;
                if (repeatLeft != null)
                {
                    repeatLeft.Click += delegate
                    {
                        if (scrollViewer != null)
                            scrollViewer.LineLeft();
                        GC.Collect();
                    };
                }

                RepeatButton repeatRight = this.Template.FindName("PART_RepeatRight", this) as RepeatButton;
                if (repeatRight != null)
                {
                    repeatRight.Click += delegate
                    {
                        if (scrollViewer != null)
                            scrollViewer.LineRight();
                        GC.Collect();
                    };
                }

                // set up the event handler for the 'New Tab' Button Click event
                ButtonBase button = this.Template.FindName("PART_NewTabButton", this) as ButtonBase;
                if (button != null)
                {
                    button.Click += delegate
                    {
                        VMukti.App.blnIsTwoPanel = false;
                        TabItem item = new TabItem();
                        item.Width = 250;
                        item.MinWidth = 250;
                        item.MaxWidth = 250;

                        item.OwnerID = VMuktiAPI.VMuktiInfo.CurrentPeer.ID;
                        item.OwnerPageIndex = VMukti.App.pageCounter++;

                        ctlPgTabHeader objPgTabHeader = new ctlPgTabHeader();
                        // objPgTabHeader.Title = "New Page - " + this.Items.Count.ToString();
                        //TextBlock txtBlock = new TextBlock();
                        //txtBlock.Text = "New Tab - " + this.Items.Count.ToString();
                        if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrentMachineIP == VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName || VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName == "")
                        {
                            objPgTabHeader.Title = "New Page";
                        }
                        else
                        {
                            objPgTabHeader.Title = VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName;
                        }
                        Image imgIcon = new Image();
                        imgIcon.Source = new BitmapImage(new Uri(@"\Skins\Images\VMuktiIcon.ico", UriKind.RelativeOrAbsolute));
                        imgIcon.Height = 16;
                        imgIcon.Width = 16;

                        //item.Header = txtBlock;
                        item.Header = objPgTabHeader;
                        item.Icon = imgIcon;

                        item.Content = NewTabControl();
                        if (VMuktiAPI.VMuktiInfo.CurrentPeer.ID > 0)
//.........这里部分代码省略.........
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:101,代码来源:TabControl.cs

示例4: OnApplyTemplate

        /*
         * Protected override methods
         *
        */
        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // set up the event handler for the template parts
            _toggleButton = this.Template.FindName("PART_DropDown", this) as ToggleButton;
            if (_toggleButton != null)
            {
                // create a context menu for the togglebutton
                System.Windows.Controls.ContextMenu cm = new ContextMenu();
                cm.PlacementTarget = _toggleButton;
                cm.Placement = PlacementMode.Bottom;

                // create a binding between the togglebutton's IsChecked Property
                // and the Context Menu's IsOpen Property
                Binding b = new Binding();
                b.Source = _toggleButton;
                b.Mode = BindingMode.TwoWay;
                b.Path = new PropertyPath(ToggleButton.IsCheckedProperty);

                cm.SetBinding(ContextMenu.IsOpenProperty, b);

                _toggleButton.ContextMenu = cm;
                _toggleButton.Checked += DropdownButton_Checked;
            }

            ScrollViewer scrollViewer = this.Template.FindName("PART_ScrollViewer", this) as ScrollViewer;

            // set up event handlers for the RepeatButtons Click event
            RepeatButton repeatLeft = this.Template.FindName("PART_RepeatLeft", this) as RepeatButton;
            if (repeatLeft != null)
            {
                repeatLeft.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineLeft();

                    GC.Collect();
                };
            }

            RepeatButton repeatRight = this.Template.FindName("PART_RepeatRight", this) as RepeatButton;
            if (repeatRight != null)
            {
                repeatRight.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineRight();

                    GC.Collect();
                };
            }

            // set up the event handler for the 'New Tab' Button Click event
            ButtonBase button = this.Template.FindName("PART_NewTabButton", this) as ButtonBase;
            if (button != null)
            {
                button.Click += delegate
                {
                    int i = this.SelectedIndex;

                    TabItem item = new TabItem();
                    item.Header = "New Tab";

                    if (i == -1 || i == this.Items.Count - 1 || AddNewTabToEnd)
                        this.Items.Add(item);
                    else
                        this.Items.Insert(++i, item);

                    if (SelectNewTabOnCreate)
                    {
                        SelectedItem = item;

                        VirtualizingTabPanel itemsHost = Helper.FindVirtualizingTabPanel(this);
                        if (itemsHost != null)
                            itemsHost.MakeVisible(item, Rect.Empty);

                        item.Focus();

                        if (TabItemSelected != null)
                            TabItemSelected(this, new TabItemEventArgs(item));
                    }

                    if (TabItemAdded != null)
                        TabItemAdded(this, new TabItemEventArgs(item));
                };
            }
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:95,代码来源:TabControl.cs


注:本文中的System.Windows.Controls.ContextMenu.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。