Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Core.Presentation / System / Activities / Presentation / TypeCollectionDesigner.xaml.cs / 1586724 / TypeCollectionDesigner.xaml.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation { using System; using System.Activities.Presentation.Model; using System.Activities.Presentation.View; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Runtime; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.ComponentModel; using System.Windows.Threading; using System.Windows.Data; [Fx.Tag.XamlVisible(false)] partial class TypeCollectionDesigner { public static readonly DependencyProperty ContextProperty = DependencyProperty.Register( "Context", typeof(EditingContext), typeof(TypeCollectionDesigner), new UIPropertyMetadata(null)); [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Type RoutedCommand is immutable.")] public static readonly ICommand AddNewTypeCommand = new RoutedCommand("AddNewType", typeof(TypeCollectionDesigner)); DataGridHelper dgHelper; ObservableCollectionwrapperCollection; public TypeCollectionDesigner() { InitializeComponent(); } // The collection of Type objects to display when type collection designer is opened. internal IEnumerable InitialTypeCollection { set { this.wrapperCollection = new ObservableCollection (value.Select(type => new TypeWrapper(type))); this.typesDataGrid.ItemsSource = this.wrapperCollection; } } // The collction of Type objects in the type collection designer when user clicks OK. public IEnumerable UpdatedTypeCollection { get { return wrapperCollection.Select(wrapper => wrapper.Type); } } public EditingContext Context { get { return (EditingContext)GetValue(ContextProperty); } set { SetValue(ContextProperty, value); } } public bool AllowDuplicate { get; set; } internal WorkflowElementDialog ParentDialog { get; set; } internal bool OnOK() { if (!this.AllowDuplicate) { List list = new List (); foreach (TypeWrapper tw in this.wrapperCollection) { if (list.Any (entry => Type.Equals(entry.Type, tw.Type))) { ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, (string)this.FindResource("duplicateEntryErrorMessage"), TypeNameHelper.GetDisplayName(tw.Type, true))); return false; } list.Add(tw); } } return true; } // The DataGrid does not bubble up KeyDown event and we expect the upper window to be closed when ESC key is down. // Thus we added an event handler in DataGrid to handle ESC key and closes the uppper window. void OnTypesDataGridRowKeyDown(object sender, KeyEventArgs args) { DataGridRow row = (DataGridRow)sender; if (args.Key == Key.Escape && !row.IsEditing && this.ParentDialog != null) { this.ParentDialog.CloseDialog(false); } } protected override void OnInitialized(EventArgs e) { this.dgHelper = new DataGridHelper(this.typesDataGrid, this); this.dgHelper.AddNewRowContent = this.FindResource("addNewRowLabel"); this.dgHelper.AddNewRowCommand = AddNewTypeCommand; base.OnInitialized(e); } void OnAddTypeExecuted(object sender, ExecutedRoutedEventArgs e) { var newEntry = new TypeWrapper(typeof(Object)); this.wrapperCollection.Add(newEntry); this.dgHelper.BeginRowEdit(newEntry); e.Handled = true; } sealed class TypeWrapper : DependencyObject { public static readonly DependencyProperty TypeProperty = DependencyProperty.Register("Type", typeof(Type), typeof(TypeWrapper)); //Default constructor is required by DataGrid to load NewItemPlaceHolder row and this constructor will never be called. //Since we've already customized the new row template and hooked over creating new object event. public TypeWrapper() { throw FxTrace.Exception.AsError(new NotSupportedException()); } public TypeWrapper(Type type) { this.Type = type; } public Type Type { get { return (Type)GetValue(TypeProperty); } set { SetValue(TypeProperty, value); } } // For screen reader to read the DataGrid row. public override string ToString() { if (this.Type != null && !string.IsNullOrEmpty(this.Type.Name)) { return this.Type.Name; } return "null"; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AlphaSortedEnumConverter.cs
- SignatureDescription.cs
- UnsafePeerToPeerMethods.cs
- HyperLinkStyle.cs
- versioninfo.cs
- Enum.cs
- Floater.cs
- UnsafeNativeMethods.cs
- ExpressionBinding.cs
- SerializeAbsoluteContext.cs
- AdornerPresentationContext.cs
- KoreanLunisolarCalendar.cs
- DescriptionAttribute.cs
- ControlParser.cs
- ControlIdConverter.cs
- SpecularMaterial.cs
- NetworkInformationPermission.cs
- OrderedDictionary.cs
- PathBox.cs
- WebPartZoneCollection.cs
- EventMappingSettingsCollection.cs
- OleDbParameterCollection.cs
- SqlFactory.cs
- LineGeometry.cs
- DiscoveryDocument.cs
- MethodBuilderInstantiation.cs
- DtrList.cs
- HttpRuntimeSection.cs
- MissingMemberException.cs
- PackageRelationshipSelector.cs
- NodeCounter.cs
- FormattedTextSymbols.cs
- OpenTypeLayout.cs
- Roles.cs
- WindowVisualStateTracker.cs
- TCEAdapterGenerator.cs
- BasicCellRelation.cs
- CodeVariableDeclarationStatement.cs
- PeerEndPoint.cs
- ExtentKey.cs
- SystemGatewayIPAddressInformation.cs
- WindowsComboBox.cs
- SecurityCriticalDataForSet.cs
- WindowsAuthenticationEventArgs.cs
- DesignBindingConverter.cs
- TablePatternIdentifiers.cs
- FunctionNode.cs
- TextSpan.cs
- ContextMenu.cs
- ProfessionalColors.cs
- CompatibleIComparer.cs
- BookmarkCallbackWrapper.cs
- WebPartVerbCollection.cs
- SystemWebExtensionsSectionGroup.cs
- DeriveBytes.cs
- EntityModelSchemaGenerator.cs
- EFColumnProvider.cs
- NavigatorOutput.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- SqlEnums.cs
- CatalogPartCollection.cs
- FormsAuthenticationModule.cs
- FileFormatException.cs
- InkPresenter.cs
- XmlSchemaObject.cs
- XmlSchemaSimpleType.cs
- FixedFindEngine.cs
- HtmlInputSubmit.cs
- XmlSchemaSet.cs
- EndOfStreamException.cs
- PersonalizationStateInfoCollection.cs
- NamespaceListProperty.cs
- MenuItemBindingCollection.cs
- InfoCardSchemas.cs
- BindingExpressionBase.cs
- SoapCommonClasses.cs
- MissingFieldException.cs
- WmlValidatorAdapter.cs
- ConfigurationManagerHelper.cs
- DashStyles.cs
- MessageQueueTransaction.cs
- CellTreeNodeVisitors.cs
- ConstraintCollection.cs
- ipaddressinformationcollection.cs
- HitTestWithPointDrawingContextWalker.cs
- SvcMapFileSerializer.cs
- CacheEntry.cs
- EntityDataSource.cs
- SemanticBasicElement.cs
- TcpProcessProtocolHandler.cs
- ImageField.cs
- CompositeFontInfo.cs
- SoapObjectInfo.cs
- DelayedRegex.cs
- ExtendedPropertyCollection.cs
- Certificate.cs
- namescope.cs
- ProfileGroupSettings.cs
- RightsManagementErrorHandler.cs
- ColorTransform.cs