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


C# Controls.ItemsControl类代码示例

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


ItemsControl类属于System.Windows.Controls命名空间,在下文中一共展示了ItemsControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartDragDrop

        public void StartDragDrop(ItemsControl source, FrameworkElement sourceItemContainer, object draggedData, Point initialMousePosition)
        {
            _topWindow = Window.GetWindow(source);
            Debug.Assert(_topWindow != null);
            _source = source;
            _sourceItemContainer = sourceItemContainer;
            _initialMousePosition = initialMousePosition;

            _initialMouseOffset = _initialMousePosition - _sourceItemContainer.TranslatePoint(new Point(0, 0), _topWindow);

            var data = new DataObject(Format.Name, draggedData);

            // Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target.
            bool previousAllowDrop = _topWindow.AllowDrop;
            _topWindow.AllowDrop = true;
            _topWindow.DragEnter += TopWindow_DragEnter;
            _topWindow.DragOver += TopWindow_DragOver;
            _topWindow.DragLeave += TopWindow_DragLeave;

            DragDrop.DoDragDrop(_source, data, DragDropEffects.Move);

            // Without this call, there would be a bug in the following scenario: Click on a data item, and drag
            // the mouse very fast outside of the window. When doing this really fast, for some reason I don't get
            // the Window leave event, and the dragged adorner is left behind.
            // With this call, the dragged adorner will disappear when we release the mouse outside of the window,
            // which is when the DoDragDrop synchronous method returns.
            RemoveDraggedAdorner();

            _topWindow.AllowDrop = previousAllowDrop;
            _topWindow.DragEnter -= TopWindow_DragEnter;
            _topWindow.DragOver -= TopWindow_DragOver;
            _topWindow.DragLeave -= TopWindow_DragLeave;
        }
开发者ID:rmunn,项目名称:cog,代码行数:33,代码来源:ItemsControlDragDrop.cs

示例2: FindNextSibling

 internal static ItemsControl FindNextSibling(ItemsControl itemsControl)
 {
     ItemsControl parentIc = ItemsControl.ItemsControlFromItemContainer(itemsControl);
     if (parentIc == null) return null;
     int index = parentIc.ItemContainerGenerator.IndexFromContainer(itemsControl);
     return parentIc.ItemContainerGenerator.ContainerFromIndex(index + 1) as ItemsControl; // returns null if index to large or nothing found
 }
开发者ID:YoshihiroIto,项目名称:TreeViewEx,代码行数:7,代码来源:TreeViewElementFinder.cs

示例3: PopulateItem

        private void PopulateItem(HtmlNode htmlNode, ItemsControl item)
        {
            var attributes = new TreeViewItem { Header = "Attributes" };
            foreach (var att in htmlNode.Attributes)
                attributes.Items.Add(new TreeViewItem
                {
                    Header = string.Format("{0} = {1}", att.OriginalName, att.Value),
                    DataContext = att
                });
            //If we don't have any attributes, don't add the node
            if (attributes.Items.Count > 0)
                item.Items.Add(attributes);

            //Create the Elements Collection
            var elements = new TreeViewItem { Header = "Elements", DataContext = htmlNode };
            foreach (var node in htmlNode.ChildNodes)
            {
                try
                {
                    //If there are no attributes, no need to add a node inbetween the parent in the treeview
                    if (attributes.Items.Count > 0)
                        elements.Items.Add(BuildTree(node));
                    else
                        item.Items.Add(BuildTree(node));
                }
                catch(InvalidOperationException e)
                {
                    //Debugger.Break();
                }
            }

            //If there are no nodes in the elements collection, don't add to the parent 
            if (elements.Items.Count > 0)
                item.Items.Add(elements);
        }
开发者ID:nscaife,项目名称:Evernote2OneNote,代码行数:35,代码来源:NodeTreeView.xaml.cs

示例4: ShowResourcesGained_DataContextChanged

        private void ShowResourcesGained_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            RollDiceAction rollDice = e.NewValue as RollDiceAction;
            Dictionary<GamePlayer, ResourceList> result = rollDice.PlayersResources;

            basePanel.Children.Clear();

            foreach (KeyValuePair<GamePlayer, ResourceList> kvp in result)
            {
                // add list of resources
                ItemsControl resources = new ItemsControl();

                FrameworkElementFactory stackPanelElement = new FrameworkElementFactory(typeof(StackPanel));
                stackPanelElement.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                resources.ItemsPanel = new ItemsPanelTemplate() { VisualTree = stackPanelElement};
                resources.Height = 90;

                Binding binding = new Binding()
                {
                    Converter = new ResourceConverter()
                };
                FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image));
                imageElement.SetBinding(Image.SourceProperty, binding);
                imageElement.SetValue(Image.HeightProperty, 80.0);
                imageElement.SetValue(Image.WidthProperty, 80.0);

                resources.ItemTemplate = new DataTemplate()
                {
                    VisualTree = imageElement
                };
                basePanel.Children.Add(resources);
                resources.ItemsSource = kvp.Value;
            }
        }
开发者ID:generateui,项目名称:SettleIn,代码行数:34,代码来源:ShowResourcesGained.xaml.cs

示例5: showTmplGroup

        public static object showTmplGroup(string addStr, ItemsControl itemFrame, RoutedEventHandler rehClick, string rowId = "")
        {
            object retItemFrame = null;

            if (MainWindow.s_pW.m_docConf.SelectSingleNode("Config").SelectSingleNode("template") != null &&
                MainWindow.s_pW.m_docConf.SelectSingleNode("Config").SelectSingleNode("template").SelectSingleNode(addStr + "Tmpls") != null)
            {
                XmlElement xeTmpls = (XmlElement)MainWindow.s_pW.m_docConf.SelectSingleNode("Config").
                    SelectSingleNode("template").SelectSingleNode(addStr + "Tmpls");
                retItemFrame = showTmpl(itemFrame, xeTmpls, addStr, rehClick, rowId);
            }

            if (Project.Setting.s_docProj.SelectSingleNode("BoloUIProj").SelectSingleNode("template") != null &&
                Project.Setting.s_docProj.SelectSingleNode("BoloUIProj").SelectSingleNode("template").SelectSingleNode(addStr + "Tmpls") != null)
            {
                XmlElement xeTmpls = (XmlElement)Project.Setting.s_docProj.SelectSingleNode("BoloUIProj").
                    SelectSingleNode("template").SelectSingleNode(addStr + "Tmpls");
                object ret = showTmpl(itemFrame, xeTmpls, addStr, rehClick, rowId);

                if (ret != null)
                {
                    retItemFrame = ret;
                }
            }

            return retItemFrame;
        }
开发者ID:jaffrykee,项目名称:ui,代码行数:27,代码来源:XmlItemContextMenu.xaml.cs

示例6: GetItem

		private UIElement GetItem (ItemsControl itemsControl, int index)
		{
			var item = (UIElement) itemsControl.ItemContainerGenerator.ContainerFromIndex (index);
			if (item == null)
				item = itemsControl.Items [index] as UIElement;
			return item;
		}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:ItemsControlAutomationPeer.cs

示例7: FillLayers

			private void FillLayers(ItemsControl root)
			{
				foreach (var dwgLayer in dwgDocument.GetLayers())
				{
					var layerItem = new TreeViewItem
					{
						Header = dwgLayer.Name
					};

					FillEntities(layerItem, dwgLayer);
					root.Items.Add(layerItem);

					// Помещаем в таблицу соответствующий слой при его выделении в дереве
					var dwgLayerCopy = dwgLayer;
					layerItem.Selected += delegate(object sender, RoutedEventArgs args)
						{
							// Отсеиваем маршрутизируемые события от дочерних узлов
							if (layerItem.Equals(args.Source) && propertyGrid != null)
								propertyGrid.SelectedObject = dwgLayerCopy;
						};

					// Повторяем в дереве изменения значений имен слоев в таблице
					dwgLayerCopy.NameChanged += (sender, newName) => layerItem.Header = newName;
				}
			}
开发者ID:mvdtom,项目名称:AcadEntitiesEditor,代码行数:25,代码来源:Dialog.xaml.cs

示例8: Sort

 public static void Sort(ItemsControl listView, string sortBy, ListSortDirection direction)
 {
     listView.Items.SortDescriptions.Clear();
     var sd = new SortDescription(sortBy, direction);
     listView.Items.SortDescriptions.Add(sd);
     listView.Items.Refresh();
 }
开发者ID:naeemkhedarun,项目名称:ShoutcastBrowser,代码行数:7,代码来源:GridViewColumnSorter.cs

示例9: RemoveItem

 public static void RemoveItem(ItemsControl itemsControl, object item)
 {
     if (item != null)
     {
         int index = itemsControl.Items.IndexOf(item);
         if (index != -1)
         {
             if (itemsControl.ItemsSource != null)
             {
                 IList iList = itemsControl.ItemsSource as IList;
                 if (iList != null)
                 {
                     iList.Remove(item);
                 }
                 else
                 {
                     Type type = itemsControl.ItemsSource.GetType();
                     Type genericList = type.GetInterface("IList`1");
                     if (genericList != null)
                     {
                         type.GetMethod("RemoveAt").Invoke(itemsControl.ItemsSource, new object[] { index });
                     }
                 }
             }
             else
             {
                 itemsControl.Items.Remove(item);
             }
         }
     }
 }
开发者ID:wtain,项目名称:FinCalc,代码行数:31,代码来源:ItemsControlHelper.cs

示例10: AddItem

 public static void AddItem(ItemsControl itemsControl, object item, int insertIndex)
 {
     if (itemsControl.Items.IndexOf(item) == -1)
     {
         if (itemsControl.ItemsSource != null)
         {
             IList iList = itemsControl.ItemsSource as IList;
             if (iList != null)
             {
                 iList.Add(item);
             }
             else
             {
                 Type type = itemsControl.ItemsSource.GetType();
                 Type genericList = type.GetInterface("IList`1");
                 if (genericList != null)
                 {
                     type.GetMethod("Insert").Invoke(itemsControl.ItemsSource, new object[] { insertIndex, item });
                 }
             }
         }
         else
         {
             itemsControl.Items.Add(item);
         }
     }
 }
开发者ID:wtain,项目名称:FinCalc,代码行数:27,代码来源:ItemsControlHelper.cs

示例11: switch

        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
                case 1:
                    this.mainGrid = (Grid) target;
                    return;

                case 2:
                    this.storageAreaChooserPanel = (Popup) target;
                    this.storageAreaChooserPanel.PreviewKeyDown += new KeyEventHandler(this.storageAreaChooserPanel_PreviewKeyDown);
                    return;

                case 3:
                    this.chooser = (ListBox) target;
                    this.chooser.SelectionChanged += new SelectionChangedEventHandler(this.chooser_SelectionChanged);
                    this.chooser.MouseUp += new MouseButtonEventHandler(this.chooser_MouseUp);
                    return;

                case 4:
                    this.storageAreaChooserButton = (Button) target;
                    this.storageAreaChooserButton.Click += new RoutedEventHandler(this.OnStorageAreaChooserButtonClick);
                    return;

                case 5:
                    this.gaugeBar = (ItemsControl) target;
                    return;

                case 6:
                    this.gaugeLegend = (ItemsControl) target;
                    return;
            }
            this._contentLoaded = true;
        }
开发者ID:netonjm,项目名称:WindowsPhone,代码行数:34,代码来源:StorageGaugePanel.cs

示例12: ToPopup

        public static Popup ToPopup(this IContextMenu source)
        {
            Popup popup = new Popup();
            // this offset assumes the phone is in portrait orientation.
            popup.VerticalOffset = 32;

            ItemsControl items = new ItemsControl();
            foreach(var item in source.Items)
            {
                Button button = new Button();
                button.Content = item.Header;
                button.Command = new RelayCommand<object>(
                    (param) => { popup.IsOpen = false; item.Command.Execute(param); },
                    (param) => item.Command.CanExecute(param));

                button.CommandParameter = item.CommandParameter;
                button.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                items.Items.Add(button);
            }

            Border border = new Border();
            border.Padding = new System.Windows.Thickness(12);
            border.MinWidth = 480;
            border.Background = App.Current.Resources["PhoneChromeBrush"] as Brush;
            border.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            border.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            border.Child = items;

            popup.Child = border;
            return popup;
        }
开发者ID:jarkkom,项目名称:awfuldotnet,代码行数:31,代码来源:IContextMenuExtensions.cs

示例13: FindItemToSelect

        // Search through items in TreeView to select one.
        bool FindItemToSelect(ItemsControl ctrl, string strSource)
        {
            foreach (object obj in ctrl.Items)
            {
                System.Xml.XmlElement xml = obj as System.Xml.XmlElement;
                string strAttribute = xml.GetAttribute("Source");
                TreeViewItem item = (TreeViewItem)
                    ctrl.ItemContainerGenerator.ContainerFromItem(obj);

                // If the TreeViewItem matches the Frame URI, select the item.
                if (strAttribute != null && strAttribute.Length > 0 &&
                                            strSource.EndsWith(strAttribute))
                {
                    if (item != null && !item.IsSelected)
                        item.IsSelected = true;

                    return true;
                }

                // Expand the item to search nested items.
                if (item != null)
                {
                    bool isExpanded = item.IsExpanded;
                    item.IsExpanded = true;

                    if (item.HasItems && FindItemToSelect(item, strSource))
                        return true;

                    item.IsExpanded = isExpanded;
                }
            }
            return false;
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:34,代码来源:HelpWindow.cs

示例14: ExpandSubContainers

 private static void ExpandSubContainers(ItemsControl parentContainer)
 {
     foreach (
         var currentContainer in
             parentContainer.Items.Cast<object>()
                            .Select(
                                item =>
                                parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem)
                            .Where(
                                currentContainer => currentContainer != null && currentContainer.Items.Count > 0)
         )
     {
         currentContainer.IsExpanded = true;
         if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
         {
             currentContainer.ItemContainerGenerator.StatusChanged += delegate
                 {
                     ExpandSubContainers(currentContainer);
                 };
         }
         else
         {
             ExpandSubContainers(currentContainer);
         }
     }
 }
开发者ID:randomgeekdom,项目名称:ForkTale,代码行数:26,代码来源:DesignerView.xaml.cs

示例15: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (this.Template != null)
            {
                var today = DateTime.Today;

                _gridRoot = GetTemplateChild("PART_Root") as Grid;
                _labelTitle = GetTemplateChild("PART_TitleHeader") as Label;
                _titleWeekDayNames = GetTemplateChild("PART_TitleDayNames") as ItemsControl;
                _days = GetTemplateChild("PART_Days") as ItemsControl;

                PreviousButtonElement = GetTemplateChild("PART_PreviousButton") as Button;
                NextButtonElement = GetTemplateChild("PART_NextButton") as Button;

                var dateFormat = GetCurrentDateFormat();
                _labelTitle.Content = String.Concat(dateFormat.GetMonthName(today.Month).ToUpper(), " ", today.Year);

                foreach (var name in dateFormat.DayNames)
                {
                    _titleWeekDayNames.Items.Add(name.ToUpper());
                }

                var day = new DateTime(today.Year, today.Month, 1);
                var lastDay = DateTime.DaysInMonth(today.Year, today.Month);
                for (int i = 1; i < lastDay; i++)
                {
                    _days.Items.Add(day.Day);

                    day = day.AddDays(1);
                }
            }
        }
开发者ID:nikitadev,项目名称:TravelpayoutsAPI,代码行数:34,代码来源:MetroCalendar.cs


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