MenuItem AddMenuItem(ItemCollection items, string header, MyMenuInfo menuInfo) { var menuItem = menuInfo.CreateMenuItem(header); items.Add(menuItem); return menuItem; }
private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { var selectedText = Globals.ThisAddIn.Application.Selection; var treeItem = (TreeViewItem)DocumentMapTreeView.SelectedItem; var mappedItem = default(MappedItem); if (treeItem == null) { mappedItem = DocumentMapping.AddMappedItem(selectedText.Text); } else { if (!DocumentMapping.Current.MappedItemDictionary.ContainsKey(treeItem.Tag.ToString())) { throw new Exception($"Document map does not contain the item {treeItem.Tag.ToString()}"); } var parentMappedItem = (MappedItem)DocumentMapping.Current.MappedItemDictionary[treeItem.Tag.ToString()]; mappedItem = DocumentMapping.AddMappedItem(selectedText.Text, parentMappedItem); } if (mappedItem != default(MappedItem)) { controls.ItemCollection itemCollection = treeItem != null ? treeItem.Items : DocumentMapTreeView.Items; TreeViewController.CreateTreeViewItems(itemCollection, new List <MappedItem> { mappedItem }, MappedTreeViewItem_Click).Await(); } }
private IList<Document> ExtractScope(ItemCollection items) { IList<Document> docs = new List<Document>(); foreach (SearchResultListItem2 item in items) docs.Add(item.Source); return docs; }
public static void AddKeyBindings(this swi.InputBindingCollection bindings, swc.ItemCollection items) { foreach (var item in items.OfType <sw.UIElement>()) { bindings.AddKeyBindings(item); } }
public ItemContainerManager(ItemsControl itemsControl) { _itemCollection = itemsControl.Items; _containerToItem = new Dictionary<DependencyObject, object>(); _itemToContainer = new Dictionary<object, DependencyObject>(); }
private TreeViewItem FindNode(TreeViewItem parentNode, ItemCollection nodes, string directory, int attemptNumber = 1) { if (attemptNumber < 1) throw new ArgumentOutOfRangeException("attemptNumber", attemptNumber, "attemptNumber must be >= 1"); if (attemptNumber > 2) { return parentNode; } List<TreeViewItem> childNodes = new List<TreeViewItem>(); foreach (TreeViewItem childNode in nodes) { childNodes.Add(childNode); DirectoryTreeNode dirNode = childNode as DirectoryTreeNode; if (dirNode == null) continue; if (string.Compare(dirNode.Directory, directory, true) == 0) { return dirNode; } } UpdateNodeChildren((DirectoryTreeNode)parentNode); TreeViewItem node = FindNode(parentNode, parentNode.Items, directory, attemptNumber + 1); return node; }
public static List<Rect> Pack(int W, int H, ItemCollection rects) { var simple = _findSimpleSolutions(W,H,rects); if (simple != null) { return simple; } Rects = rects; string result=""; result += W.ToString()+" "+H.ToString()+" "+ rects.Count.ToString()+"\r\n"; foreach (Rect item in rects) { result += item.Width + " " + item.Height+"\r\n"; } File.WriteAllText("cSharpBridge.txt", result); Process p = Process.Start("RectingAlgorithmProcess.exe"); p.WaitForExit(); FileStream fs = new FileStream("cPlusPlusBridge.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs); int n = Convert.ToInt32(reader.ReadLine()); List<Rect> temp = new List<Rect>(); Rect t = new Rect(); for (int i = 0; i < n; i++) { t.X = Convert.ToInt32(reader.ReadLine()); t.Y = Convert.ToInt32(reader.ReadLine()); int id = Convert.ToInt32(reader.ReadLine()); t.Width = ((Rect)Rects[id]).Width; t.Height = ((Rect)Rects[id]).Height; t.SName = ((Rect)Rects[id]).SName; temp.Add(t); } return temp; }
// InnerItemCollectionView will return itself as SourceCollection (SourceCollection property is overridden); // shouldProcessCollectionChanged is turned off because this class will handle its own events. public InnerItemCollectionView(int capacity, ItemCollection itemCollection) : base(EmptyEnumerable.Instance, false) { // This list is cloned and diverged when Sort/Filter is applied. _rawList = _viewList = new ArrayList(capacity); _itemCollection = itemCollection; }
public MainWindow() { InitializeComponent(); _ListViewItem = NTabItem_Work.NListViewControl.NView.Items; _WorkModelItemControl_L = NTabItem_Work.WorkModelControl_L; _WorkModelItemControl_R = NTabItem_Work.WorkModelControl_R; }
private void CreateItemCollectionAndGenerator() { _items = new ItemCollection(this); // the generator must attach its collection change handler before // the control itself, so that the generator is up-to-date by the // time the control tries to use it (bug 892806 et al.) _itemContainerGenerator = new ItemContainerGenerator(this); _itemContainerGenerator.ChangeAlternationCount(); ((INotifyCollectionChanged)_items).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemCollectionChanged); if (IsInitPending) { _items.BeginInit(); } else if (IsInitialized) { _items.BeginInit(); _items.EndInit(); } ((INotifyCollectionChanged)_groupStyle).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupStyleChanged); }
public ContractController(MainWindow contractView) { this.contractView = contractView; DisplayItems = contractView.contracts.Items; generationTimer.Tick += generationTimer_Tick; generationTimer.Interval = TimeSpan.FromSeconds(1); contractModel.Subscribe(this); }
private static void ChangeCheckedState(bool isChecked, ItemCollection ic) { foreach (var obj in ic) { var dir = obj as DirectoryEntry; if (dir != null) ChangeState(isChecked, dir); } }
private void UpdateView(ItemCollection itemCollection, IEnumerable<String> items) { itemCollection.Clear(); foreach (var item in items) { var description = String.IsNullOrEmpty(item) ? "Unknown" : item; itemCollection.Add(description); } }
public PanoramaView(PanoramaControl parent) { Parent = parent; LayoutRoot = parent.LayoutRoot; Items = Parent.Items; BackgroundHost.Transform = new TranslateTransform(); TitleHost.Transform = new TranslateTransform(); ItemsHost.Transform = new TranslateTransform(); }
MenuItem AddMenuItem(ItemCollection items, string header, ICommand command) { var menuItem = new MenuItem(); menuItem.Header = header; menuItem.Command = command; items.Add(menuItem); return menuItem; }
private void AddTreeViewItem(ItemCollection items, WorkItem workItem) { bool firstChild = (items.Count == 0); WorkItemTreeViewItem item = new WorkItemTreeViewItem(workItem); items.Add(item); if (firstChild && (item.Parent is WorkItemTreeViewItem)) { (item.Parent as WorkItemTreeViewItem).IsExpanded = true; } }
void CopyKeyBindings(swc.ItemCollection items) { foreach (var item in items.OfType <swc.MenuItem>()) { Control.InputBindings.AddRange(item.InputBindings); if (item.HasItems) { CopyKeyBindings(item.Items); } } }
public PivotView(PivotControl parent) { Parent = parent; LayoutRoot = Parent.LayoutRoot; HeadersPanel = Parent.HeadersPanel; Headers = HeadersPanel.Children; Items = Parent.Items; HeadersHost.Transform = new TranslateTransform(); ItemsHost.Transform = new TranslateTransform(); }
private static string _itemSerializer(ItemCollection items, int maxWeight,int alg) { string result = alg.ToString()+"\r\n"; result += maxWeight + "\r\n"; result += items.Count.ToString() + "\r\n"; foreach (KnapsackObject obj in items) { result += obj.Name + " " + obj.Weight + " " + obj.Price + "\r\n"; } return result; }
public void ItemCollectionDefaultViewTest() { ItemCollection itemCollection = new ItemCollection(); NotifyCollectionChangedEventArgs lastChangeArgs = null; itemCollection.CollectionChanged += (sender, e) => lastChangeArgs = e; itemCollection.Add("default1"); Assert.AreEqual(NotifyCollectionChangedAction.Add, lastChangeArgs.Action); CollectionAssert.AreEqual(new[] { "default1" }, lastChangeArgs.NewItems.Cast<string>().ToArray()); }
public OrdersRootViewModel(ItemCollection tabs) { Instance = this; this.Tabs = tabs; FillTabs(); LoadContent = new DelegateCommand( () => { //this.SelectedItem = Node.GetSelectedItem(this.Projects); }, () => { return true; } ); BackgroundWorker worker = new BackgroundWorker(); ProjectsRingVisibility = true; PersonsRingVisibility = true; InfoProjectsRingVisibility = true; InfoUsersRingVisibility = true; worker.DoWork += new DoWorkEventHandler((sender, e) => { /* var comm = new Command(DatabaseManager.Instance.Connection); Cache.CacheManager.Instance.Freelancers = DatabaseLoader.ComputeFreelansers(comm); Cache.CacheManager.Instance.Costumers = DatabaseLoader.ComputeCostumers(comm); Cache.CacheManager.Instance.Tasks = DatabaseLoader.ComputeTasks(comm); Cache.CacheManager.Instance.Projects = DatabaseLoader.ComputeProjects(comm); var nodes = new ObservableCollection<MVVM.Node>(Cache.CacheManager.Instance.Projects.Select(x => x as Node).ToList());*/ Random rand = new Random(); rand.Next(0, 1500); //System.Threading.Thread.Sleep(2000); Projects = FillProjects(); Peoples = FillCostumers(); ProjectsRingVisibility = false; PersonsRingVisibility = false; InfoProjectsRingVisibility = false; InfoUsersRingVisibility = false; }); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender,e) => { }); worker.RunWorkerAsync(); }
private void add_children(ItemCollection group, int? id) { foreach (KeyValuePair<int,MarketGroup> mg in market_groups) { if (mg.Value.parent_id == id) { TreeViewItem item = new TreeViewItem(); item.Header = mg.Value.name; item.Tag = mg.Key; if (!mg.Value.has_types) add_children(item.Items, mg.Key); group.Add(item); } } }
private static bool AddToChildren(ItemCollection itemCollection, MenuItem newItem, string parent) { foreach (MenuItem item in itemCollection) { if (item.Name == parent) { item.Items.Add(newItem); return true; } if (AddToChildren(item.Items, newItem, parent)) return true; } return false; }
void Remove(ItemCollection items, Stack<string> headers) { var header = headers.Pop(); if (headers.Count == 0) { RemoveMenuItem(items, header); } else { var m = Find(items, header); Remove(m.Items, headers); } }
private static void BuildTree(OfflineDynamicPage rootDp, ItemCollection rootItems) { var tvItem = new TreeViewItem { Header = rootDp.RussianTitle, Tag = rootDp, }; rootItems.Add(tvItem); foreach (var item in rootDp.Childs) { BuildTree(item, tvItem.Items); } }
public static KnapsackSolution FindSolutionFullSearchV1(ItemCollection items,int maxWeight) { File.WriteAllText("cSharpBridge.txt",_itemSerializer(items,maxWeight,0)); Process p = Process.Start("KnapsackAlgorighmProcess.exe"); p.WaitForExit(); ulong result = Convert.ToUInt64(File.ReadAllText("cPlusPlusBridge.txt")); List<KnapsackObject> temp = new List<KnapsackObject>(); for (int i = 0; i < items.Count; i++) { if (((KnapsackObject)items[i]).Weight <= maxWeight) { temp.Add((KnapsackObject)items[i]); } } return new KnapsackSolution(result, items, maxWeight); }
public void LoadFilesAndFolders(ItemCollection items) { items.Clear(); String folderPath = ""; //Get path to the current users files if (Session.GetInstance().UserID != -1) folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\sliceofpie\\" + Session.GetInstance().Email; else folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\sliceofpie\\"; //Create a DirectoryInfo for that folder DirectoryInfo dir = new DirectoryInfo(folderPath); //Insert dictionaries and files from the folder as items in treeview GetInstance().InsertDirectoriesIntoDirectory(items, dir); GetInstance().InsertFilesIntoDirectory(items, dir); }
private static TreeViewItem ContainerFromItem(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection, object item) { foreach (object curChildItem in itemCollection) { TreeViewItem parentContainer = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (parentContainer == null) return null; TreeViewItem containerThatMightContainItem = (TreeViewItem)parentContainer.ItemContainerGenerator.ContainerFromItem(item); if (containerThatMightContainItem != null) return containerThatMightContainItem; TreeViewItem recursionResult = ContainerFromItem(parentContainer.ItemContainerGenerator, parentContainer.Items, item); if (recursionResult != null) return recursionResult; } return null; }
private static object ItemFromContainer(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection, TreeViewItem container) { foreach (object curChildItem in itemCollection) { TreeViewItem parentContainer = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (parentContainer == null) return null; TreeViewItem itemThatMightBelongToContainer = (TreeViewItem)parentContainer.ItemContainerGenerator.ItemFromContainer(container); if (itemThatMightBelongToContainer != null) return itemThatMightBelongToContainer; TreeViewItem recursionResult = ItemFromContainer(parentContainer.ItemContainerGenerator, parentContainer.Items, container) as TreeViewItem; if (recursionResult != null) return recursionResult; } return null; }
private TreeViewItem FindParentTreeViewNode(ItemCollection viewItemCollection, string nodeName) { foreach (TreeViewItem node in viewItemCollection) { if (node == null || node.Header == null) { throw new Exception(); } // breadth-first walk if (node.Header.ToString().Equals(nodeName)) { return node; } } return null; }
public void UpdateSummaryRow(ItemCollection _itemCollection) { SummaryOrder summaryRow = new SummaryOrder(); summaryRow.IsAggregatedRow = true; summaryRow.StrategyName = "Totals:"; summaryRow.Status = string.Empty; for (int i = 0; i < _itemCollection.Count; i++) { SummaryOrder orderInfo = _itemCollection[i] as SummaryOrder; if (orderInfo != null) { summaryRow.OpenOrders += orderInfo.OpenOrders; summaryRow.PnL += orderInfo.PnL; summaryRow.UR_PnL += orderInfo.UR_PnL; summaryRow.PositionShares += orderInfo.PositionShares; summaryRow.PositionAmount += orderInfo.PositionAmount; summaryRow.RebateRevenue += orderInfo.RebateRevenue; summaryRow.TradingRevenue += orderInfo.TradingRevenue; summaryRow.Volume += orderInfo.Volume; summaryRow.TotalCount += orderInfo.TotalCount; summaryRow.TradingCount += orderInfo.TradingCount; summaryRow.MaxLoss += orderInfo.MaxLoss; summaryRow.SeedRemaining += orderInfo.SeedRemaining; } } summaryRow.SymbolTrading = string.Format("{0} of {1}", summaryRow.TradingCount, summaryRow.TotalCount); if (summaryRow.Volume != 0) { summaryRow.PnLPerShares = summaryRow.PnL / summaryRow.Volume; } else { summaryRow.PnLPerShares = 0; } App.AppManager.RunOnDispatcherThread(() => { if (App.AppManager.DataMgr.AggregateSummaryInfo.Count > 0) { App.AppManager.DataMgr.AggregateSummaryInfo[0] = summaryRow; } //App.AppManager.DataMgr.AggregateSummaryInfo.Clear(); //App.AppManager.DataMgr.AggregateSummaryInfo.Add(summaryRow); }); }
private void GenerateButtons(ItemCollection items) { //每个Command都生成一个具体的按钮 foreach (var command in this.CommandMetaGroup.Commands) { var group = new CommandMetaGroup(command.Name); group.AddCommand(command); var menuGenerator = new MenuItemGenerator { CommandMetaGroup = group, Context = this.Context }; var control = menuGenerator.CreateControl(); items.Add(control); } }
private void populateComboBox(ItemCollection Items) { foreach (TreeViewItem item in Items) { if ((bool)((object[])item.Tag)[2] == true) { ComboBoxItem comboItem = new ComboBoxItem(); comboItem.Content = item.Header; comboItem.Tag = item.Tag; comboBoxFolders.Items.Add(comboItem); if (item.Items.Count > 0) { populateComboBox(item.Items); } } } }
public async static Task CreateTreeViewItems(controls.ItemCollection itemCollection, IList <MappedItem> mappedItems, string selectedTreeItemId = null) { foreach (var item in mappedItems) { var treeViewItem = new controls.TreeViewItem() { Header = item.Name, Tag = item.Id, IsSelected = string.IsNullOrEmpty(selectedTreeItemId) && selectedTreeItemId == item.Id.ToString() ? true : false }; if (item.ChildMappedItems.Any()) { await CreateTreeViewItems(treeViewItem.Items, item.ChildMappedItems); } itemCollection.Add(treeViewItem); } }
public async static Task CreateTreeViewItems(controls.ItemCollection itemCollection, IList <MappedItem> mappedItems, Action <object, RoutedEventArgs> addItemClick) { foreach (var item in mappedItems) { var treeViewItem = new controls.TreeViewItem() { Tag = item.Id, }; var button = new controls.Button() { Content = "Add", Tag = item.Id.ToString(), Height = 14, Margin = new System.Windows.Thickness(10, 0, 0, 0) }; button.Click += new System.Windows.RoutedEventHandler(addItemClick); var sp = new controls.StackPanel(); sp.Height = 20; sp.Orientation = System.Windows.Controls.Orientation.Horizontal; sp.Children.Add(new System.Windows.Controls.Label() { Content = item.Name }); sp.Children.Add(button); sp.Children[1].Visibility = Visibility.Hidden; treeViewItem.Header = sp; if (item.ChildMappedItems.Any()) { await CreateTreeViewItems(treeViewItem.Items, item.ChildMappedItems, addItemClick); } itemCollection.Add(treeViewItem); } }
/// <summary> /// Preset the UI with the current Settings /// </summary> private void updateUiWithCurrentSettings() { // Set the Combox Params for the ClientServer Selection cbFunctionSelection.ItemsSource = new string[] { "Single RS232", "Single TCP", "Multi" }; cbClientServerSelect.ItemsSource = new string[] { "Client", "Server" }; System.Windows.Controls.ItemCollection selectedItem = tcTabControl.Items; foreach (System.Windows.Controls.TabItem item in tcTabControl.Items) { if (item.Header.Equals("TCP IP") && userSettings.currentConnectionSetting == 1) { tcTabControl.SelectedItem = item; } else if (item.Header.Equals("RS232") && userSettings.currentConnectionSetting == 2) { tcTabControl.SelectedItem = item; } } setUiRs232Settings(); setUiTcpIpSettings(); }
WpfControls.MenuItem FindMenuItem(string text, WpfControls.ItemCollection items) { foreach (object item in items) { if (item is WpfControls.MenuItem mi) { if (mi.Header.ToString().StartsWithEx(text) && mi.Header.ToString().TrimEx() == text) { return(mi); } if (mi.Items.Count > 0) { WpfControls.MenuItem val = FindMenuItem(text, mi.Items); if (val != null) { return(val); } } } } return(null); }
private void AddProperties(SceneElement targetElement, ResourceEntryItem resource, System.Windows.Controls.ItemCollection menuItems) { Type filterType = (Type)null; bool flag = true; if (PlatformTypes.Brush.IsAssignableFrom((ITypeId)resource.Resource.Type)) { filterType = typeof(Brush); } else if (PlatformTypes.DrawingImage.IsAssignableFrom((ITypeId)resource.Resource.Type)) { filterType = typeof(ImageSource); } else if (PlatformTypes.PlatformsCompatible(resource.Resource.ValueNode.Type.PlatformMetadata, targetElement.Type.PlatformMetadata)) { IType styleOrTemplateType; ITypeId typeAndTargetType = DocumentNodeUtilities.GetStyleOrTemplateTypeAndTargetType(resource.Resource.ValueNode, out styleOrTemplateType); if (typeAndTargetType != null) { flag = typeAndTargetType.IsAssignableFrom((ITypeId)targetElement.Type); filterType = styleOrTemplateType.RuntimeType; } } else { flag = false; } if (!flag) { return; } int count = menuItems.Count; this.AddElementPropertiesWithTypeFilter(targetElement, resource, menuItems, filterType); if (menuItems.Count != count) { return; } this.AddElementPropertiesWithTypeFilter(targetElement, resource, menuItems, (Type)null); }
/// <summary> /// Called by consumers of TextSearch when a TextInput event is received /// to kick off the algorithm. /// </summary> /// <param name="nextChar"></param> /// <returns></returns> internal bool DoSearch(string nextChar) { bool repeatedChar = false; int startItemIndex = 0; ItemCollection itemCollection = _attachedTo.Items as ItemCollection; // If TextSearch is not active, then we should start // the search from the beginning. If it is active, we should // start the search from the currently-matched item. if (IsActive) { // ISSUE: This falls victim to duplicate elements being in the view. // To mitigate this, we could remember ItemUI ourselves. startItemIndex = MatchedItemIndex; } // If they pressed the same character as last time, we will do the fallback search. // Fallback search is if they type "bob" and then press "b" // we'll look for "bobb" and when we don't find it we should // find the next item starting with "bob". if (_charsEntered.Count > 0 && (String.Compare(_charsEntered[_charsEntered.Count - 1], nextChar, true, GetCulture(_attachedTo)) == 0)) { repeatedChar = true; } // Get the primary TextPath from the ItemsControl to which we are attached. string primaryTextPath = GetPrimaryTextPath(_attachedTo); bool wasNewCharUsed = false; int matchedItemIndex = FindMatchingPrefix(_attachedTo, primaryTextPath, Prefix, nextChar, startItemIndex, repeatedChar, ref wasNewCharUsed); // If there was an item that matched, move to that item in the collection if (matchedItemIndex != -1) { // Don't have to move currency if it didn't actually move. // startItemIndex is the index of the current item only if IsActive is true, // So, we have to move currency when IsActive is false. if (!IsActive || matchedItemIndex != startItemIndex) { object matchedItem = itemCollection[matchedItemIndex]; // Let the control decide what to do with matched-item _attachedTo.NavigateToItem(matchedItem, matchedItemIndex, new ItemsControl.ItemNavigateArgs(Keyboard.PrimaryDevice, ModifierKeys.None)); // Store current match MatchedItemIndex = matchedItemIndex; } // Update the prefix if it changed if (wasNewCharUsed) { AddCharToPrefix(nextChar); } // User has started typing (successfully), so we're active now. if (!IsActive) { IsActive = true; } } // Reset the timeout and remember this character, but only if we're // active -- this is because if we got called but the match failed // we don't need to set up a timeout -- no state needs to be reset. if (IsActive) { ResetTimeout(); } return(matchedItemIndex != -1); }
/// <summary> /// Searches through the given itemCollection for the first item matching the given prefix. /// </summary> /// <remarks> /// -------------------------------------------------------------------------- /// Incremental Type Search algorithm /// -------------------------------------------------------------------------- /// /// Given a prefix and new character, we loop through all items in the collection /// and look for an item that starts with the new prefix. If we find such an item, /// select it. If the new character is repeated, we look for the next item after /// the current one that begins with the old prefix**. We can optimize by /// performing both of these searches in parallel. /// /// **NOTE: Win32 will only do this if the old prefix is of length 1 - in other /// words, first-character-only matching. The algorithm described here /// is an extension of ITS as implemented in Win32. This variant was /// described to me by JeffBog as what was done in AFC - but I have yet /// to find a listbox which behaves this way. /// /// -------------------------------------------------------------------------- /// </remarks> /// <returns>Item that matches the given prefix</returns> private static int FindMatchingPrefix(ItemsControl itemsControl, string primaryTextPath, string prefix, string newChar, int startItemIndex, bool lookForFallbackMatchToo, ref bool wasNewCharUsed) { ItemCollection itemCollection = itemsControl.Items; // Using indices b/c this is a better way to uniquely // identify an element in the collection. int matchedItemIndex = -1; int fallbackMatchIndex = -1; int count = itemCollection.Count; // Return immediately with no match if there were no items in the view. if (count == 0) { return(-1); } string newPrefix = prefix + newChar; // With an empty prefix, we'd match anything if (String.IsNullOrEmpty(newPrefix)) { return(-1); } // Hook up the binding we will apply to each object. Get the // PrimaryTextPath off of the attached instance and then make // a binding with that path. BindingExpression primaryTextBinding = null; object item0 = itemsControl.Items[0]; bool useXml = SystemXmlHelper.IsXmlNode(item0); if (useXml || !String.IsNullOrEmpty(primaryTextPath)) { primaryTextBinding = CreateBindingExpression(itemsControl, item0, primaryTextPath); TextValueBindingExpression.SetValue(itemsControl, primaryTextBinding); } bool firstItem = true; wasNewCharUsed = false; CultureInfo cultureInfo = GetCulture(itemsControl); // ISSUE: what about changing the collection while this is running? for (int currentIndex = startItemIndex; currentIndex < count;) { object item = itemCollection[currentIndex]; if (item != null) { string itemString = GetPrimaryText(item, primaryTextBinding, itemsControl); bool isTextSearchCaseSensitive = itemsControl.IsTextSearchCaseSensitive; // See if the current item matches the newPrefix, if so we can // stop searching and accept this item as the match. if (itemString != null && itemString.StartsWith(newPrefix, !isTextSearchCaseSensitive, cultureInfo)) { // Accept the new prefix as the current prefix. wasNewCharUsed = true; matchedItemIndex = currentIndex; break; } // Find the next string that matches the last prefix. This // string will be used in the case that the new prefix isn't // matched. This enables pressing the last character multiple // times and cylcing through the set of items that match that // prefix. // // Unlike the above search, this search must start *after* // the currently selected item. This search also shouldn't // happen if there was no previous prefix to match against if (lookForFallbackMatchToo) { if (!firstItem && prefix != String.Empty) { if (itemString != null) { if (fallbackMatchIndex == -1 && itemString.StartsWith(prefix, !isTextSearchCaseSensitive, cultureInfo)) { fallbackMatchIndex = currentIndex; } } } else { firstItem = false; } } } // Move next and wrap-around if we pass the end of the container. currentIndex++; if (currentIndex >= count) { currentIndex = 0; } // Stop where we started but only after the first pass // through the loop -- we should process the startItem. if (currentIndex == startItemIndex) { break; } } if (primaryTextBinding != null) { // Clean up the binding for the primary text path. TextValueBindingExpression.ClearValue(itemsControl); } // In the case that the new prefix didn't match anything and // there was a fallback match that matched the old prefix, move // to that one. if (matchedItemIndex == -1 && fallbackMatchIndex != -1) { matchedItemIndex = fallbackMatchIndex; } return(matchedItemIndex); }
protected sealed override void OnItemsChanged(object sender, ItemsChangedEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } ItemCollection itemCollection = ItemsOwner?.Items; NotifyCollectionChangedAction action = args.Action; if (action == NotifyCollectionChangedAction.Reset) { OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action)); } else if (itemCollection != null) { IItemContainerGenerator itemContainerGenerator = sender as IItemContainerGenerator; if (itemContainerGenerator != null) { switch (action) { case NotifyCollectionChangedAction.Add: { int num4 = itemContainerGenerator.IndexFromGeneratorPosition(args.Position); if (args.Position.Offset == 1) { num4 = itemCollection.Count - 1; } VirtualItemsList changedItems2 = new VirtualItemsList(itemCollection, num4, args.ItemCount); if (!IsVirtualizing) { for (int k = num4; k < num4 + args.ItemCount; k++) { RealizeItem(k); } } OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, changedItems2, num4)); break; } case NotifyCollectionChangedAction.Remove: { int num5 = itemContainerGenerator.IndexFromGeneratorPosition(args.Position); ArrayList arrayList = new ArrayList(args.ItemCount); for (int l = 0; l < args.ItemUICount; l++) { UIElement uIElement = base.InternalChildren[args.Position.Index + l]; arrayList.Add(ItemFromContainer(uIElement)); if (num5 == -1) { num5 = (int)uIElement.ReadLocalValue(IndexForItemContainerProperty); } uIElement.ClearValue(IndexForItemContainerProperty); } if (args.ItemUICount > 0) { RemoveInternalChildRange(args.Position.Index, args.ItemUICount); } OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, arrayList, num5)); break; } case NotifyCollectionChangedAction.Move: { int num2 = -1; int num3 = itemContainerGenerator.IndexFromGeneratorPosition(args.Position); VirtualItemsList changedItems = new VirtualItemsList(itemCollection, num3, args.ItemCount); int itemUICount = args.ItemUICount; if (itemUICount > 0) { UIElement[] array = new UIElement[itemUICount]; for (int i = 0; i < itemUICount; i++) { array[i] = base.InternalChildren[args.OldPosition.Index + i]; if (num2 == -1) { num2 = (int)array[i].ReadLocalValue(IndexForItemContainerProperty); } } RemoveInternalChildRange(args.OldPosition.Index + Math.Min(args.OldPosition.Offset, 1), itemUICount); for (int j = 0; j < itemUICount; j++) { InsertInternalChild(args.Position.Index + j, array[j]); } } OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, changedItems, num3, num2)); break; } case NotifyCollectionChangedAction.Replace: { int num = itemContainerGenerator.IndexFromGeneratorPosition(args.Position); VirtualItemsList newItems = new VirtualItemsList(itemCollection, num, args.ItemCount); VirtualItemsList oldItems = new VirtualItemsList(null, num, args.ItemCount); OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, newItems, oldItems, num)); break; } } } } base.OnItemsChanged(sender, args); InvalidateReality(); }
public static void GetTreeViewVisibleChrildren(System.Collections.ArrayList e_Collection, System.Windows.Controls.ItemCollection e_Control) { foreach (TreeViewItem l_Item in e_Control) { if (l_Item.IsVisible) { e_Collection.Add(l_Item); if (l_Item.IsExpanded) { GetTreeViewVisibleChrildren(e_Collection, l_Item.Items); } } } }
public ItemsControl() { Items = new ItemCollection(); ItemContainerGenerator = new ItemContainerGenerator(this); }
private static object ItemFromContainer(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection, TreeViewItem container) { foreach (object curChildItem in itemCollection) { TreeViewItem parentContainer = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (parentContainer == null) { return(null); } TreeViewItem itemThatMightBelongToContainer = (TreeViewItem)parentContainer.ItemContainerGenerator.ItemFromContainer(container); if (itemThatMightBelongToContainer != null) { return(itemThatMightBelongToContainer); } TreeViewItem recursionResult = ItemFromContainer(parentContainer.ItemContainerGenerator, parentContainer.Items, container) as TreeViewItem; if (recursionResult != null) { return(recursionResult); } } return(null); }
private static TreeViewItem FindContainer(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection, Predicate <TreeViewItem> condition) { foreach (object curChildItem in itemCollection) { TreeViewItem containerThatMightMeetTheCondition = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (containerThatMightMeetTheCondition == null) { return(null); } if (condition(containerThatMightMeetTheCondition)) { return(containerThatMightMeetTheCondition); } TreeViewItem recursionResult = FindContainer(containerThatMightMeetTheCondition.ItemContainerGenerator, containerThatMightMeetTheCondition.Items, condition); if (recursionResult != null) { return(recursionResult); } } return(null); }
private static TreeViewItem ContainerFromItem(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection, object item) { foreach (object curChildItem in itemCollection) { TreeViewItem parentContainer = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (parentContainer == null) { return(null); } TreeViewItem containerThatMightContainItem = (TreeViewItem)parentContainer.ItemContainerGenerator.ContainerFromItem(item); if (containerThatMightContainItem != null) { return(containerThatMightContainItem); } TreeViewItem recursionResult = ContainerFromItem(parentContainer.ItemContainerGenerator, parentContainer.Items, item); if (recursionResult != null) { return(recursionResult); } } return(null); }
private static IEnumerable <TreeViewItem> GetTreeViewItems(ItemContainerGenerator parentItemContainerGenerator, ItemCollection itemCollection) { foreach (object curChildItem in itemCollection) { TreeViewItem container = (TreeViewItem)parentItemContainerGenerator.ContainerFromItem(curChildItem); if (container != null) { yield return(container); } foreach (var treeViewItem in GetTreeViewItems(container.ItemContainerGenerator, container.Items)) { yield return(treeViewItem); } } }
private void lblTarget_Drop_1(object sender, DragEventArgs e) { //下面我们加入坐标比较, 来实现上插入和下插入. //sender是目标时间, e里面存储了 source物品. Console.WriteLine("进入右边drop函数中了.下一个是鼠标进入的物品"); // debug找到对应的索引. System.Windows.Controls.Label sender2 = (System.Windows.Controls.Label)sender as System.Windows.Controls.Label; //必须强制转化一下才得到真真的name. c#就这样.比价傻. string aaa4 = ""; aaa4 = ((sender2 as System.Windows.Controls.Label).Name); Point p = e.GetPosition((IInputElement)sender); Console.WriteLine(7777777); Console.WriteLine(p); Console.WriteLine("鼠标在控件中的相对坐标在上一行");// Console.WriteLine(sender2.ActualHeight); Console.WriteLine("控件高度在上一行"); //所以比较 int shang = 0; if (p.Y >= sender2.ActualHeight / 2) { shang = 1; } Console.WriteLine("得到source东西是什么,鼠标从哪里来的"); string aaa3 = ((lastMoveing as System.Windows.Controls.Label).Name); Console.WriteLine(lastMoveing); Console.WriteLine("来的索引是"); Console.WriteLine(aaa3); e.Handled = true; Console.WriteLine(e.Handled); // 下面计算控件的坐标. 然后fix parent即可. System.Windows.Controls.ItemCollection item = listBox.Items; //if (item.Parent != null) item.Parent.SetValue(ContentPresenter.ContentProperty, null); ArrayList myAL = new ArrayList(); for (int i = 0; i < listBox.Items.Count; i++) { myAL.Add(listBox.Items[i]);// 根据Name进行排序.先扔着 // 遇到aaa4 就 在她前面放入aaa3 的索引即可. } ArrayList myAL2 = new ArrayList(); int memo = 0; if (myAL.Count > 1) { //找到memo for (int i = 0; i < listBox.Items.Count; i++) { if ((listBox.Items[i] as System.Windows.Controls.Label).Name == aaa3) { memo = i; break; } } Console.WriteLine("打印一下我们的判断函数hi"); Console.WriteLine(shang); if (shang == 0) { for (int i = 0; i < listBox.Items.Count; i++) { if ((listBox.Items[i] as System.Windows.Controls.Label).Name == aaa4) { myAL2.Add(listBox.Items[memo]); } //把aaa3 插入aaa4前面了. if ((listBox.Items[i] as System.Windows.Controls.Label).Name == aaa3) { continue; } ; myAL2.Add(listBox.Items[i]); } } else { for (int i = 0; i < listBox.Items.Count; i++) { if ((listBox.Items[i] as System.Windows.Controls.Label).Name == aaa3) { continue; } ; myAL2.Add(listBox.Items[i]); if ((listBox.Items[i] as System.Windows.Controls.Label).Name == aaa4) { myAL2.Add(listBox.Items[memo]); } //把aaa3 插入aaa4后了. } } } if (listBox.Items.Count > 0) { listBox.Items.Clear(); } for (int i = 0; i < myAL2.Count; i++) { listBox.Items.Add(myAL2[i]); } Console.WriteLine(); }
private void AddElementPropertiesWithTypeFilter(SceneElement targetElement, ResourceEntryItem resource, System.Windows.Controls.ItemCollection menuItems, Type filterType) { SceneNode[] selection = new SceneNode[1] { (SceneNode)targetElement }; foreach (TargetedReferenceStep targetedReferenceStep in (IEnumerable <TargetedReferenceStep>)PropertyMerger.GetMergedProperties((IEnumerable <SceneNode>)selection)) { ReferenceStep referenceStep = targetedReferenceStep.ReferenceStep; if (referenceStep.Name != "Name" && PropertyInspectorModel.IsPropertyBrowsable(selection, targetedReferenceStep) && (PropertyInspectorModel.IsAttachedPropertyBrowsable(selection, targetElement.Type, targetedReferenceStep, (ITypeResolver)targetElement.ProjectContext) && PlatformTypeHelper.GetPropertyType((IProperty)referenceStep) != (Type)null) && (PlatformTypeHelper.GetPropertyType((IProperty)referenceStep).IsAssignableFrom(resource.Resource.Type.RuntimeType) && (filterType == (Type)null || filterType.IsAssignableFrom(PlatformTypeHelper.GetPropertyType((IProperty)referenceStep))))) { menuItems.Add((object)this.BuildPropertyMenuItem(targetElement, referenceStep, resource)); } } }