ActivityTypeDesigner.xaml.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / ActivityTypeDesigner.xaml.cs / 1305376 / ActivityTypeDesigner.xaml.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.Activities.Presentation.View 
{
    using System.Linq; 
    using System.Windows; 
    using System.Windows.Controls;
    using System.Windows.Input; 
    using System.Activities.Presentation.Model;
    using System.Windows.Threading;
    using System.Activities.Presentation.Services;
    using System.Activities.Presentation.Xaml; 

    partial class ActivityTypeDesigner : IExpandChild 
    { 
        public ActivityTypeDesigner()
        { 
            this.InitializeComponent();
        }

        protected override void OnModelItemChanged(object newItem) 
        {
            base.OnModelItemChanged(newItem); 
            if (this.Context.Services.GetService() == null) 
            {
                this.Context.Services.Publish(new DisplayNameUpdater(this.Context)); 
            }
        }

        protected override void OnContextMenuLoaded(ContextMenu menu) 
        {
            base.OnContextMenuLoaded(menu); 
            if (null == this.ModelItem.Properties["Implementation"].Value) 
            {
                var toHide = menu.Items.OfType().Where(p => 
                    p.Command == DesignerView.GoToParentCommand ||
                    p.Command == DesignerView.ExpandCommand);

                foreach (var item in toHide) 
                {
                    item.Visibility = Visibility.Collapsed; 
                } 
            }
        } 


        // the job of this service is to add an attached proeprty on ActivityBuilder called displayName.
        // this name will be shown in breadcrumb bar. 
        // if ActivityBuilder.Name = "workflowconsoleApp.Sequence1"
        // we want DisplayName = "Sequence1" 
        // also whenever the Name property changes 
        // we want to refresh the DisplayName property too ( by calling displayNameProperty.NotifyPropertyChanged())
        class DisplayNameUpdater 
        {
            AttachedProperty displayNameProperty;
            public DisplayNameUpdater(EditingContext context)
            { 
                displayNameProperty = new AttachedProperty
                { 
                    Name = "DisplayName", 
                    OwnerType = typeof(ActivityBuilder),
                    Getter = (modelItem) => GetDisplayName(modelItem) 
                };
                context.Services.GetService().AddProperty(displayNameProperty);
                context.Services.GetService().ModelChanged += new EventHandler(ModelChanged);
            } 

            void ModelChanged(object sender, ModelChangedEventArgs e) 
            { 
                if (e.PropertiesChanged != null)
                { 
                    foreach (ModelProperty property in e.PropertiesChanged)
                    {
                        if (property.Parent.ItemType.Equals(typeof(ActivityBuilder)) && property.Name == "Name")
                        { 
                            displayNameProperty.NotifyPropertyChanged(property.Parent);
                        } 
                    } 
                }
            } 

            private string GetDisplayName(ModelItem modelItem)
            {
                ModelItem nameModelItem = modelItem.Properties["Name"].Value; 
                string name = (nameModelItem == null) ? null : (string)nameModelItem.GetCurrentValue();
                string displayName = string.Empty; 
                if (!string.IsNullOrEmpty(name)) 
                {
                    int indexOfDot = name.LastIndexOf('.'); 
                    if (indexOfDot > -1)
                    {
                        // if make sure there atleast one character after .
                        if (indexOfDot < name.Length - 1) 
                        {
                            displayName = name.Substring(indexOfDot + 1); 
                        } 
                    }
                    else 
                    {
                        displayName = name;
                    }
                } 
                return displayName;
            } 
        } 

 
        public ModelItem ExpandedChild
        {
            get
            { 
                ModelItem modelItemToSelect = null;
                if (this.ModelItem != null) 
                { 
                    modelItemToSelect = this.ModelItem.Properties["Implementation"].Value;
                } 
                return modelItemToSelect;
            }
        }
 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK