예제 #1
0
		protected override void CommitProperties()
		{
			IndexChangeEvent e; 
			bool changedSelection = false;
			
			base.CommitProperties();
			
			if (_dataProviderChanged)
			{
				_dataProviderChanged = false;
				DoingWholesaleChanges = false;
			
				if (_selectedIndex >= 0 && null != DataProvider && _selectedIndex < DataProvider.Length)
				   ItemSelected(_selectedIndex, true);
				else if (_requireSelection)
				   ProposedSelectedIndex = 0;
				else
				   SetSelectedIndex(-1, false);
			}
				
			if (_requireSelectionChanged)
			{
				_requireSelectionChanged = false;
				
				if (_requireSelection &&
						SelectedIndex == NO_SELECTION &&
						null != DataProvider &&
						DataProvider.Length > 0)
				{
					// Set the proposed selected index here to make sure
					// CommitSelection() is called below.
					ProposedSelectedIndex = 0;
				}
			}
			
			if (null != PendingSelectedItem)
			{
				if (null != DataProvider)
					ProposedSelectedIndex = DataProvider.GetItemIndex(PendingSelectedItem);
				
				if (AllowCustomSelectedItem && ProposedSelectedIndex == -1)
				{
					ProposedSelectedIndex = CUSTOM_SELECTED_ITEM;
					_selectedItem = PendingSelectedItem;
				}
				  
				PendingSelectedItem = null;
			}
			
			if (ProposedSelectedIndex != NO_PROPOSED_SELECTION)
				changedSelection = CommitSelection(true);
			
			// If the selectedIndex has been adjusted to account for items that
			// have been added or removed, send out a "change" event 
			// so any bindings to selectedIndex are updated correctly.
			if (SelectedIndexAdjusted)
			{
				SelectedIndexAdjusted = false;
				if (!changedSelection)
				{
					DispatchEvent(new FrameworkEvent(FrameworkEvent.VALUE_COMMIT));
				}
			}
			
			if (CaretIndexAdjusted)
			{
				CaretIndexAdjusted = false;
				if (!changedSelection)
				{
					// Put the new caretIndex renderer into the
					// caret state and dispatch an "caretChange" 
					// event to update any bindings. Additionally, update 
					// the backing variable. 
					ItemShowingCaret(_selectedIndex, true); 
					_caretIndex = _selectedIndex; 
					
					e = new IndexChangeEvent(IndexChangeEvent.CARET_CHANGE); 
					e.OldIndex = _caretIndex; 
					e.NewIndex = _caretIndex;
					DispatchEvent(e);  
				}
			}
			
			if (_labelFieldOrFunctionChanged)
			{
				_labelFieldOrFunctionChanged = false; 

				// Cycle through all instantiated renderers to push the correct text 
				// in to the renderer by setting its label property
				if (null != DataGroup)
				{
					// if virtual layout, only loop through the indices in view
					// otherwise, loop through all of the item renderers
					/*if (null != Layout && Layout.UseVirtualLayout)
					{
						foreach (int itemIndex in DataGroup.GetItemIndicesInView())
						{
							UpdateRendererLabelProperty(itemIndex);
						}
					}
					else
					{*/
						var n = DataGroup.NumberOfContentChildren;
						for (var itemIndex = 0; itemIndex < n; itemIndex++)
						{
							UpdateRendererLabelProperty(itemIndex);
						}
					/*}*/
				}
			}
		}
예제 #2
0
		/**
		 *  
		 *  The selection validation and commitment workhorse method. 
		 *  Called to commit the pending selected index. This method dispatches
		 *  the "changing" event, and if the event is not cancelled,
		 *  commits the selection change and then dispatches the "change"
		 *  event.
		 * 
		 *  Returns true if the selection was committed, or false if the selection
		 *  was cancelled.
		 */
		protected virtual bool CommitSelection(bool dispatchChangedEvents/* = true*/)
		{
			// Step 1: make sure the proposed selected index is in range.
			var maxIndex = null != DataProvider ? DataProvider.Length - 1 : -1;
			var oldSelectedIndex = _selectedIndex;
			var oldCaretIndex = _caretIndex;
			IndexChangeEvent e;
			
			if (!AllowCustomSelectedItem || ProposedSelectedIndex != CUSTOM_SELECTED_ITEM)
			{
				if (ProposedSelectedIndex < NO_SELECTION)
					ProposedSelectedIndex = NO_SELECTION;
				if (ProposedSelectedIndex > maxIndex)
					ProposedSelectedIndex = maxIndex;
				if (_requireSelection && ProposedSelectedIndex == NO_SELECTION && 
					null != DataProvider && DataProvider.Length > 0)
				{
					ProposedSelectedIndex = NO_PROPOSED_SELECTION;
					return false;
				}
			}
			
			// Step 2: dispatch the "changing" event. If preventDefault() is called
			// on this event, the selection change will be cancelled.        
			if (DispatchChangeAfterSelection)
			{
				e = new IndexChangeEvent(IndexChangeEvent.CHANGING, false, true)
						{
							OldIndex = _selectedIndex,
							NewIndex = ProposedSelectedIndex
						};
				//if (!DispatchEvent(e))
				if (e.DefaultPrevented)
				{
					// The event was cancelled. Cancel the selection change and return.
					ProposedSelectedIndex = NO_PROPOSED_SELECTION;
					return false;
				}
			}
			
			// Step 3: commit the selection change and caret change
			_selectedIndex = ProposedSelectedIndex;
			ProposedSelectedIndex = NO_PROPOSED_SELECTION;
			
			if (oldSelectedIndex != NO_SELECTION)
				ItemSelected(oldSelectedIndex, false);
			if (_selectedIndex != NO_SELECTION && _selectedIndex != CUSTOM_SELECTED_ITEM)
				ItemSelected(_selectedIndex, true);
			SetCurrentCaretIndex(_selectedIndex); 

			// Step 4: dispatch the "change" event and "caretChange" 
			// events based on the dispatchChangeEvents parameter. Overrides may  
			// chose to dispatch the change/caretChange events 
			// themselves, in which case we wouldn't want to dispatch the event 
			// here. 
			if (dispatchChangedEvents)
			{
				// Dispatch the change event
				if (DispatchChangeAfterSelection)
				{
					e = new IndexChangeEvent(IndexChangeEvent.CHANGE)
							{
								OldIndex = oldSelectedIndex,
								NewIndex = _selectedIndex
							};
					DispatchEvent(e);
					DispatchChangeAfterSelection = false;
				}
				else
				{
					DispatchEvent(new FrameworkEvent(FrameworkEvent.VALUE_COMMIT));
				}
				
				//Dispatch the caretChange event 
				e = new IndexChangeEvent(IndexChangeEvent.CARET_CHANGE)
						{
							OldIndex = oldCaretIndex,
							NewIndex = _caretIndex
						};
				DispatchEvent(e);
			}
			
			return true;
		 }
예제 #3
0
 /**
  *  
  */
 private void DispatchChangeEvent(int oldIndex, int newIndex)
 {
     var e = new IndexChangeEvent(Event.CHANGE)
                 {
                     OldIndex = oldIndex,
                     NewIndex = newIndex,
                     RelatedObject = GetChildAt(newIndex)
                 };
     DispatchEvent(e);
 }