コード例 #1
0
        public void Deny_Unrestricted()
        {
            DataBindingCollection dbc = new DataBindingCollection();

            Assert.AreEqual(0, dbc.Count, "Count");
            Assert.IsFalse(dbc.IsReadOnly, "IsReadOnly");
            Assert.IsFalse(dbc.IsSynchronized, "IsSynchronized");
            dbc.Add(db);
            Assert.AreSame(db, dbc["property"], "this[string]");
            Assert.IsNotNull(dbc.RemovedBindings, "RemovedBindings");
            Assert.IsNotNull(dbc.SyncRoot, "SyncRoot");
            Assert.IsNotNull(dbc.GetEnumerator(), "GetEnumerator");
            dbc.CopyTo(new DataBinding[1], 0);
            dbc.Clear();

            dbc.Add(db);
            dbc.Remove(db);

            dbc.Add(db);
            dbc.Remove("property");
            dbc.Remove("property", true);
            dbc.Changed += new EventHandler(Handler);
            Assert.IsFalse(dbc.Contains("property"), "Contains");
            dbc.Changed -= new EventHandler(Handler);
        }
コード例 #2
0
 private void OnOKButtonClick(object sender, EventArgs e)
 {
     if (this._bindingsDirty)
     {
         ExpressionBindingCollection expressions  = ((IExpressionsAccessor)this.Control).Expressions;
         DataBindingCollection       dataBindings = ((IDataBindingsAccessor)this.Control).DataBindings;
         expressions.Clear();
         foreach (BindablePropertyNode node in this._bindablePropsTree.Nodes)
         {
             if (node.IsBound)
             {
                 expressions.Add(node.Binding);
                 if (dataBindings.Contains(node.Binding.PropertyName))
                 {
                     dataBindings.Remove(node.Binding.PropertyName);
                 }
             }
         }
         foreach (ExpressionBinding binding in this._complexBindings.Values)
         {
             expressions.Add(binding);
         }
     }
     base.DialogResult = DialogResult.OK;
     base.Close();
 }
コード例 #3
0
        /// <include file='doc\UserControlDesigner.uex' path='docs/doc[@for="ControlDesigner.OnBindingsCollectionChanged"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Delegate to
        ///       handle bindings collection changed event.
        ///    </para>
        /// </devdoc>
        protected override void OnBindingsCollectionChanged(string propName)
        {
            if (Behavior == null)
            {
                return;
            }

            DataBindingCollection bindings = DataBindings;

            if (propName != null)
            {
                DataBinding db = bindings[propName];

                string persistPropName = propName.Replace('.', '-');

                if (db == null)
                {
                    Behavior.RemoveAttribute(persistPropName, true);
                }
                else
                {
                    string bindingExpr = "<%# " + db.Expression + " %>";
                    Behavior.SetAttribute(persistPropName, bindingExpr, true);

                    if (persistPropName.IndexOf('-') < 0)
                    {
                        // We only reset top-level properties to be consistent with
                        // what we do the other way around, i.e., when a databound
                        // property value is set to some value
                        ResetPropertyValue(persistPropName);
                    }
                }
            }
            else
            {
                string[] removedBindings = bindings.RemovedBindings;
                foreach (string s in removedBindings)
                {
                    string persistPropName = s.Replace('.', '-');
                    Behavior.RemoveAttribute(persistPropName, true);
                }

                foreach (DataBinding db in bindings)
                {
                    string bindingExpr     = "<%# " + db.Expression + " %>";
                    string persistPropName = db.PropertyName.Replace('.', '-');

                    Behavior.SetAttribute(persistPropName, bindingExpr, true);
                    if (persistPropName.IndexOf('-') < 0)
                    {
                        // We only reset top-level properties to be consistent with
                        // what we do the other way around, i.e., when a databound
                        // property value is set to some value
                        ResetPropertyValue(persistPropName);
                    }
                }
            }
        }
コード例 #4
0
        private static void PersistDataBoundLiteralControl(TextWriter sw, DesignerDataBoundLiteralControl control)
        {
            Debug.Assert(((IDataBindingsAccessor)control).HasDataBindings == true);

            DataBindingCollection bindings    = ((IDataBindingsAccessor)control).DataBindings;
            DataBinding           textBinding = bindings["Text"];

            Debug.Assert(textBinding != null, "Did not get a Text databinding from DesignerDataBoundLiteralControl");

            if (textBinding != null)
            {
                sw.Write("<%# ");
                sw.Write(textBinding.Expression);
                sw.Write(" %>");
            }
        }
コード例 #5
0
        /// <summary>
        ///    <para>
        ///       Persists the data bindings of the specified control using the specified
        ///       string writer.
        ///    </para>
        /// </summary>
        /// <param name='sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' control'>
        ///    The control to use.
        /// </param>
        private static void PersistDataBindings(TextWriter sw, Control control)
        {
            DataBindingCollection bindings    = ((IDataBindingsAccessor)control).DataBindings;
            IEnumerator           bindingEnum = bindings.GetEnumerator();

            while (bindingEnum.MoveNext())
            {
                DataBinding db = (DataBinding)bindingEnum.Current;
                string      persistPropName = db.PropertyName.Replace('.', '-');

                sw.Write(" ");
                sw.Write(persistPropName);
                sw.Write("='<%# ");
                sw.Write(HttpUtility.HtmlEncode(db.Expression));
                sw.Write(" %>'");
            }
        }
コード例 #6
0
        // Override the DataBindControl to set property values in
        // the DataBindingCollection at design time.
        public override void DataBindControl(IDesignerHost designerHost,
                                             Control control)
        {
            DataBindingCollection bindings =
                ((IDataBindingsAccessor)control).DataBindings;
            DataBinding imageBinding = bindings["ImageUrl"];

            // If Text is empty, supply a default value.
            if (!(imageBinding == null))
            {
                CustomHyperLink hype = (CustomHyperLink)control;
                hype.ImageUrl = "Image URL.";
            }

            // Call the base method to bind the control.
            base.DataBindControl(designerHost, control);
        } // DataBindControl
コード例 #7
0
        /// <include file='doc\DataGridGeneralPage.uex' path='docs/doc[@for="DataGridGeneralPage.SaveComponent"]/*' />
        /// <devdoc>
        ///   Saves the component loaded into the page.
        /// </devdoc>
        protected override void SaveComponent()
        {
            DataGrid dataGrid = (DataGrid)GetBaseControl();

            dataGrid.ShowHeader   = showHeaderCheck.Checked;
            dataGrid.ShowFooter   = showFooterCheck.Checked;
            dataGrid.AllowSorting = allowSortingCheck.Checked;

            string dataKeyField = String.Empty;

            if (dataKeyFieldCombo.IsSet())
            {
                dataKeyField = (string)dataKeyFieldCombo.SelectedItem;
            }
            dataGrid.DataKeyField = dataKeyField;

            if (dataSourceDirty)
            {
                // save the datasource as a binding on the control

                DataGridDesigner      dataGridDesigner = (DataGridDesigner)GetBaseDesigner();
                DataBindingCollection dataBindings     = dataGridDesigner.DataBindings;

                if (currentDataSource == null)
                {
                    dataGridDesigner.DataSource = String.Empty;
                    dataGridDesigner.DataMember = String.Empty;
                }
                else
                {
                    dataGridDesigner.DataSource = currentDataSource.ToString();

                    if (dataMemberCombo.IsSet())
                    {
                        dataGridDesigner.DataMember = (string)dataMemberCombo.SelectedItem;
                    }
                    else
                    {
                        dataGridDesigner.DataMember = String.Empty;
                    }
                }

                dataGridDesigner.OnDataSourceChanged();
            }
        }
コード例 #8
0
        public override void DataBindControl(IDesignerHost designerHost, Control control)
        {
            DataBindingCollection dataBindings = ((IDataBindingsAccessor)control).DataBindings;
            DataBinding           binding      = dataBindings["Text"];
            DataBinding           binding2     = dataBindings["NavigateUrl"];

            if ((binding != null) || (binding2 != null))
            {
                HyperLink link = (HyperLink)control;
                if (binding != null)
                {
                    link.Text = System.Design.SR.GetString("Sample_Databound_Text");
                }
                if (binding2 != null)
                {
                    link.NavigateUrl = "url";
                }
            }
        }
コード例 #9
0
        [Test] public void ChangeTest()
        {
            DataBindingCollection a = new DataBindingCollection();

            a.Changed += delegate {
                changed = true;
            };

            DataBinding b = new DataBinding("a", typeof(DataBindingCollectionTest), "b");

            a.Add(b);
            Assert.AreEqual(true, changed, "DB1");
            changed = false;

            a.Clear();
            Assert.AreEqual(false, changed, "DB2");

            a.Remove(b);
            Assert.AreEqual(true, changed, "DB3");
        }
コード例 #10
0
        /// <include file='doc\HyperLinkDataBindingHandler.uex' path='docs/doc[@for="HyperLinkDataBindingHandler.DataBindControl"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override void DataBindControl(IDesignerHost designerHost, Control control)
        {
            DataBindingCollection bindings    = ((IDataBindingsAccessor)control).DataBindings;
            DataBinding           textBinding = bindings["Text"];
            DataBinding           urlBinding  = bindings["NavigateUrl"];

            if ((textBinding != null) || (urlBinding != null))
            {
                HyperLink hyperLink = (HyperLink)control;

                if (textBinding != null)
                {
                    hyperLink.Text = SR.GetString(SR.Sample_Databound_Text);
                }
                if (urlBinding != null)
                {
                    // any value will do, we just need an href to be rendered
                    hyperLink.NavigateUrl = "url";
                }
            }
        }
コード例 #11
0
        /// <summary>
        ///    <para>
        ///       Persists the inner properties of the control.
        ///    </para>
        /// </summary>
        /// <param name='sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name='host'>
        ///    The services interface exposed by the webforms designer.
        /// </param>
        internal static void PersistInnerProperties(TextWriter sw, object component, IDesignerHost host)
        {
            PropertyDescriptorCollection propDescs = TypeDescriptor.GetProperties(component);

            for (int i = 0; i < propDescs.Count; i++)
            {
                // Only deal with inner attributes that need to be persisted
                if (propDescs[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                PersistenceModeAttribute persistenceMode = (PersistenceModeAttribute)propDescs[i].Attributes[typeof(PersistenceModeAttribute)];
                if (persistenceMode.Mode == PersistenceMode.Attribute)
                {
                    continue;
                }

                if (propDescs[i].PropertyType == typeof(string))
                {
                    // String based property...

                    DataBindingCollection dataBindings = null;
                    if (component is IDataBindingsAccessor)
                    {
                        dataBindings = ((IDataBindingsAccessor)component).DataBindings;
                    }
                    if (dataBindings == null || dataBindings[propDescs[i].Name] == null)
                    {
                        PersistenceMode mode = persistenceMode.Mode;
                        if ((mode == PersistenceMode.InnerDefaultProperty) ||
                            (mode == PersistenceMode.EncodedInnerDefaultProperty))
                        {
                            PersistStringProperty(sw, component, propDescs[i], mode);
                        }
                        else
                        {
                            Debug.Fail("Cannot persist inner string property marked with PersistenceMode.InnerProperty");
                        }
                    }
                }
                else if (typeof(ITemplate).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Template based property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistTemplateProperty(sw, component, propDescs[i]);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist template property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
/* AUI change 03/21/01 */
                else if (propDescs[i].DisplayName.Equals("Templates") &&
                         component is DeviceSpecificChoice &&
                         typeof(IDictionary).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    IDictionary templateCollection = (IDictionary)propDescs[i].GetValue(component);
                    foreach (String templateName in templateCollection.Keys)
                    {
                        ITemplate template = (ITemplate)templateCollection[templateName];
                        PersistTemplateProperty(sw, templateName, template);
                    }
                }
/* End of AUI change*/
                else if (typeof(ICollection).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Collection based property...
                    if ((persistenceMode.Mode == PersistenceMode.InnerProperty) ||
                        (persistenceMode.Mode == PersistenceMode.InnerDefaultProperty))
                    {
                        PersistCollectionProperty(sw, component, propDescs[i], persistenceMode.Mode, host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist collection property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty or PersistenceMode.InnerDefaultProperty");
                    }
                }
                else
                {
                    // Other complex property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistComplexProperty(sw, component, propDescs[i], host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist complex property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
            }
        }
コード例 #12
0
        /// <include file='doc\WebControlPersister.uex' path='docs/doc[@for="ControlPersister.PersistAttributes"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Persists the properties of a tag.
        ///    </para>
        /// </devdoc>
        private static void PersistAttributes(TextWriter sw, object component, string prefix, PropertyDescriptor propDesc)
        {
            PropertyDescriptorCollection properties;
            string persistPrefix = String.Empty;
            object value         = component;

            if (propDesc != null)
            {
                value      = propDesc.GetValue(component);
                properties = TypeDescriptor.GetProperties(propDesc.PropertyType,
                                                          new Attribute[] {
                    PersistenceModeAttribute.Attribute
                });
            }
            else
            {
                properties = TypeDescriptor.GetProperties(component,
                                                          new Attribute[] {
                    PersistenceModeAttribute.Attribute
                });
            }

            if (value == null)
            {
                return;
            }

            if (prefix.Length != 0)
            {
                persistPrefix = prefix + "-";
            }

            DataBindingCollection dataBindings = null;
            bool isControl = (component is Control);

            if ((component is IDataBindingsAccessor))
            {
                dataBindings = ((IDataBindingsAccessor)component).DataBindings;
            }

            for (int i = 0; i < properties.Count; i++)
            {
                // Skip properties that are hidden to the serializer
                if (properties[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                // Skip design-time only properties such as DefaultModifiers and Name
                DesignOnlyAttribute doAttr = (DesignOnlyAttribute)properties[i].Attributes[typeof(DesignOnlyAttribute)];
                if ((doAttr != null) && doAttr.IsDesignOnly)
                {
                    continue;
                }

                string propName = properties[i].Name;
                Type   propType = properties[i].PropertyType;

                object obj = properties[i].GetValue(value);
                if (obj == null)
                {
                    continue;
                }

                DefaultValueAttribute defValAttr =
                    (DefaultValueAttribute)properties[i].Attributes[typeof(DefaultValueAttribute)];
                if ((defValAttr != null) && (obj.Equals(defValAttr.Value)))
                {
                    continue;
                }

                string persistName = propName;
                if (prefix.Length != 0)
                {
                    persistName = persistPrefix + persistName;
                }

                PropertyDescriptorCollection subProps = null;
                if (properties[i].SerializationVisibility == DesignerSerializationVisibility.Content)
                {
                    subProps = TypeDescriptor.GetProperties(propType);
                }
                if ((subProps == null) || (subProps.Count == 0))
                {
                    string persistValue = null;

                    // TODO: Use consts or have DataBinding store both OM name and persist name
                    DataBinding db = null;
                    if (dataBindings != null)
                    {
                        db = dataBindings[persistName.Replace('.', '-')];
                    }

                    if (db == null)
                    {
                        if (propType.IsEnum)
                        {
                            persistValue = Enum.Format(propType, obj, "G");
                        }
                        else if (propType == typeof(string))
                        {
                            persistValue = HttpUtility.HtmlEncode(obj.ToString());
                        }
                        else
                        {
                            TypeConverter converter = properties[i].Converter;
                            if (converter != null)
                            {
                                persistValue = converter.ConvertToInvariantString(null, obj);
                            }
                            else
                            {
                                persistValue = obj.ToString();
                            }
                            persistValue = HttpUtility.HtmlEncode(persistValue);
                        }

                        if ((persistValue == null) ||
                            (persistValue.Equals("NotSet")) ||
                            (propType.IsArray && (persistValue.Length == 0)))
                        {
                            continue;
                        }

                        sw.Write(" ");
                        sw.Write(persistName);
                        sw.Write("=\"");

                        sw.Write(persistValue);
                        sw.Write("\"");
                    }
                }
                else
                {
                    // there are sub properties, don't persist this object, but
                    // recursively persist the subproperties.
                    PersistAttributes(sw, obj, persistName, null);
                }
            }

            // Persist all the databindings on this control
            if (isControl)
            {
                PersistDataBindings(sw, (Control)component);

                AttributeCollection expandos = null;
                if (component is WebControl)
                {
                    expandos = ((WebControl)component).Attributes;
                }
                else if (component is HtmlControl)
                {
                    expandos = ((HtmlControl)component).Attributes;
                }
                else if (component is UserControl)
                {
                    expandos = ((UserControl)component).Attributes;
                }

                if (expandos != null)
                {
                    foreach (string key in expandos.Keys)
                    {
                        sw.Write(" ");
                        sw.Write(key);
                        sw.Write("=\"");
                        sw.Write(expandos[key]);
                        sw.Write("\"");
                    }
                }
            }
        }
コード例 #13
0
        protected override void OnBindingsCollectionChanged(string propName)
        {
            // This method actually forms an DataBindingExpression of the design time and associates it to the Property of the Control.
            IHtmlControlDesignerBehavior myHtmlControlDesignBehavior = Behavior;
            DataBindingCollection        myDataBindingCollection;
            DataBinding myDataBinding1, myDataBinding2;
            String      myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2;

            string[]    removedBindings1, removedBindings2;
            Int32       temp;
            IEnumerator myEnumerator;

            if (myHtmlControlDesignBehavior == null)
            {
                return;
            }
// <Snippet8>
            DataBindingCollection myDataBindingCollection1 = new DataBindingCollection();

            myDataBindingCollection1 = myDataBindingCollection = DataBindings;
// </Snippet8>

            if (propName != null)
            {
                myDataBinding1   = myDataBindingCollection[propName];
                myStringReplace1 = propName.Replace(".", "-");
                if (myDataBinding1 == null)
                {
                    myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1, true);
                    return;
                }
                // DataBinding is not null.
                myDataBindingExpression1 = String.Concat("<%#", myDataBinding1.Expression, "%>");
                myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1, true);
                int index = myStringReplace1.IndexOf("-");
            }
            else
            {
// <Snippet9>
                removedBindings2 = removedBindings1 = DataBindings.RemovedBindings;
// </Snippet9>
                temp = 0;
                while (removedBindings2.Length > temp)
                {
                    removedBinding             = removedBindings2[temp];
                    removedBindingAfterReplace = removedBinding.Replace('.', '-');
                    myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace, true);
                    temp = temp + 1;
                }
// <Snippet10>
                myDataBindingCollection = DataBindings;
                myEnumerator            = myDataBindingCollection.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
// <Snippet11>
// <Snippet12>
                    myDataBinding2 = (DataBinding)myEnumerator.Current;
                    String dataBindingOutput1, dataBindingOutput2, dataBindingOutput3;
                    dataBindingOutput1 = String.Concat("The property name is ", myDataBinding2.PropertyName);
                    dataBindingOutput2 = String.Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1);
                    dataBindingOutput3 = String.Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2);
                    WriteToFile(dataBindingOutput3);
// </Snippet12>
// </Snippet11>
                    myDataBindingExpression2 = String.Concat("<%#", myDataBinding2.Expression, "%>");
                    myStringReplace2         = myDataBinding2.PropertyName.Replace(".", "-");
                    myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2, true);
                    int index = myStringReplace2.IndexOf('-');
                }// while loop ends
// </Snippet10>
// <Snippet13>
// <Snippet14>
// <Snippet15>
                string dataBindingOutput4, dataBindingOutput5, dataBindingOutput6, dataBindingOutput7, dataBindingOutput8;
                dataBindingOutput4 = String.Concat("The Count of the collection is ", myDataBindingCollection1.Count);
                dataBindingOutput5 = String.Concat("The IsSynchronised property of the collection is ", myDataBindingCollection1.IsSynchronized, "-", dataBindingOutput4);
                dataBindingOutput6 = String.Concat("The IsReadOnly property of the collection is ", myDataBindingCollection1.IsReadOnly, "-", dataBindingOutput5);
                WriteToFile(dataBindingOutput6);
// </Snippet15>
// </Snippet14>
// </Snippet13>

// <Snippet16>
                System.Array dataBindingCollectionArray = Array.CreateInstance(typeof(object), myDataBindingCollection1.Count);
                myDataBindingCollection1.CopyTo(dataBindingCollectionArray, 0);
                dataBindingOutput7 = String.Concat("The count of DataBindingArray is  ", dataBindingCollectionArray.Length);
                WriteToFile(dataBindingOutput7);
// </Snippet16>
                IEnumerator myEnumerator1 = myDataBindingCollection1.GetEnumerator();
                if (myEnumerator1.MoveNext())
                {
// <Snippet17>

                    myDataBinding1     = (DataBinding)myEnumerator1.Current;
                    dataBindingOutput8 = String.Concat("The HashCode is", myDataBinding1.GetHashCode().ToString());
                    WriteToFile(dataBindingOutput8);
// <Snippet18>
                    myDataBindingCollection1.Remove(myDataBinding1);
                    dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet18>
// </Snippet17>
                }
                else
                {
                    myDataBinding1 = (DataBinding)myEnumerator1.Current;
// <Snippet19>
                    myDataBindingCollection1.Remove("Text", true);
                    dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet19>
// <Snippet20>
                    myDataBindingCollection1.Clear();
                    dataBindingOutput8 = String.Concat("The Count of the collection after clear method is called  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet20>
                }
            } // else ends here.
        }
コード例 #14
0
        /// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValues"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Gets the fields present within the selected data source if information about them is available.
        ///    </para>
        /// </devdoc>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            object[]   names                 = null;
            String     dataMember            = null;
            bool       autoGenerateFields    = false;
            bool       autoGenerateFieldsSet = false;
            ObjectList objectList            = null;

            if (context != null)
            {
                ArrayList list = new ArrayList();

                PropertyDescriptorCollection props = null;

                IComponent component = context.Instance as IComponent;
                if (component is IDeviceSpecificChoiceDesigner)
                {
                    Object             owner = ((ChoicePropertyFilter)component).Owner;
                    PropertyDescriptor pd    =
                        ((ICustomTypeDescriptor)component).GetProperties()[_dataMemberPropertyName];
                    Debug.Assert(pd != null, "Cannot get DataMember");

                    if (owner is ObjectList)
                    {
                        autoGenerateFields    = ((ObjectList)owner).AutoGenerateFields;
                        autoGenerateFieldsSet = true;
                    }

                    component = ((IDeviceSpecificChoiceDesigner)component).UnderlyingControl;

                    // See if owner already has a DataMember
                    dataMember = (String)pd.GetValue(owner);
                    Debug.Assert(dataMember != null);
                    if (dataMember == String.Empty)
                    {
                        // Get it from underlying object.
                        dataMember = (String)pd.GetValue(component);
                        Debug.Assert(dataMember != null);
                    }
                }

                if (component != null)
                {
                    objectList = component as ObjectList;

                    if (objectList != null)
                    {
                        foreach (ObjectListField field in objectList.Fields)
                        {
                            list.Add(field.Name);
                        }

                        if (!autoGenerateFieldsSet)
                        {
                            autoGenerateFields = objectList.AutoGenerateFields;
                        }
                    }

                    if (objectList == null || autoGenerateFields)
                    {
                        ISite componentSite = component.Site;
                        if (componentSite != null)
                        {
                            IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost));
                            if (designerHost != null)
                            {
                                IDesigner designer = designerHost.GetDesigner(component);

                                if (designer is IDataSourceProvider)
                                {
                                    IEnumerable dataSource = null;
                                    if (dataMember != null && dataMember != String.Empty)
                                    {
                                        DataBindingCollection dataBindings =
                                            ((HtmlControlDesigner)designer).DataBindings;
                                        DataBinding binding = dataBindings[_dataSourcePropertyName];
                                        if (binding != null)
                                        {
                                            dataSource =
                                                DesignTimeData.GetSelectedDataSource(
                                                    component,
                                                    binding.Expression,
                                                    dataMember);
                                        }
                                    }
                                    else
                                    {
                                        dataSource =
                                            ((IDataSourceProvider)designer).GetResolvedSelectedDataSource();
                                    }

                                    if (dataSource != null)
                                    {
                                        props = DesignTimeData.GetDataFields(dataSource);
                                    }
                                }
                            }
                        }
                    }
                }

                if (props != null)
                {
                    foreach (PropertyDescriptor propDesc in props)
                    {
                        list.Add(propDesc.Name);
                    }
                }

                names = list.ToArray();
                Array.Sort(names);
            }
            return(new StandardValuesCollection(names));
        }
コード例 #15
0
        /// <include file='doc\DataListGeneralPage.uex' path='docs/doc[@for="DataListGeneralPage.SaveComponent"]/*' />
        /// <devdoc>
        ///   Saves the component loaded into the page.
        /// </devdoc>
        protected override void SaveComponent()
        {
            DataList dataList = (DataList)GetBaseControl();

            dataList.ShowHeader = showHeaderCheck.Checked;
            dataList.ShowFooter = showFooterCheck.Checked;

            try {
                int    repeatColumns      = 1;
                string repeatColumnsValue = repeatColumnsEdit.Text.Trim();
                if (repeatColumnsValue.Length != 0)
                {
                    repeatColumns = Int32.Parse(repeatColumnsValue, CultureInfo.InvariantCulture);
                }
                dataList.RepeatColumns = repeatColumns;
            } catch (Exception) {
                repeatColumnsEdit.Text = (dataList.RepeatColumns).ToString();
            }

            switch (repeatDirectionCombo.SelectedIndex)
            {
            case IDX_DIR_HORIZONTAL:
                dataList.RepeatDirection = RepeatDirection.Horizontal;
                break;

            case IDX_DIR_VERTICAL:
                dataList.RepeatDirection = RepeatDirection.Vertical;
                break;
            }

            switch (repeatLayoutCombo.SelectedIndex)
            {
            case IDX_MODE_TABLE:
                dataList.RepeatLayout = RepeatLayout.Table;
                break;

            case IDX_MODE_FLOW:
                dataList.RepeatLayout = RepeatLayout.Flow;
                break;
            }

            dataList.ExtractTemplateRows = extractRowsCheck.Checked;

            string dataKeyField = String.Empty;

            if (dataKeyFieldCombo.IsSet())
            {
                dataKeyField = (string)dataKeyFieldCombo.SelectedItem;
            }
            dataList.DataKeyField = dataKeyField;

            if (dataSourceDirty)
            {
                DataListDesigner dataListDesigner = (DataListDesigner)GetBaseDesigner();

                // save the datasource as a binding on the control
                DataBindingCollection dataBindings = dataListDesigner.DataBindings;

                if (currentDataSource == null)
                {
                    dataListDesigner.DataSource = String.Empty;
                    dataListDesigner.DataMember = String.Empty;
                }
                else
                {
                    dataListDesigner.DataSource = currentDataSource.ToString();
                    if (dataMemberCombo.IsSet())
                    {
                        dataListDesigner.DataMember = (string)dataMemberCombo.SelectedItem;
                    }
                    else
                    {
                        dataListDesigner.DataMember = String.Empty;
                    }
                }

                dataListDesigner.OnDataSourceChanged();
            }
        }
コード例 #16
0
        /// <summary>
        ///   Saves the component loaded into the page.
        /// </summary>
        protected override void SaveComponent()
        {
            ObjectList         objectList         = (ObjectList)GetBaseControl();
            ObjectListDesigner objectListDesigner = (ObjectListDesigner)GetBaseDesigner();

            String labelField = String.Empty;

            if (_cmbLabelField.IsSet())
            {
                labelField = (String)_cmbLabelField.SelectedItem;
            }
            objectList.LabelField = labelField;

            String tableFields = String.Empty;

            foreach (String field in _xLists.GetSelectedItems())
            {
                tableFields += (field + ";");
            }
            objectList.TableFields = tableFields;

            if (_dataSourceDirty)
            {
                // save the datasource as a binding on the control
                DataBindingCollection dataBindings = objectListDesigner.DataBindings;

                if (_currentDataSource == null)
                {
                    objectListDesigner.DataSource = String.Empty;
                    objectListDesigner.DataMember = String.Empty;
                }
                else
                {
                    objectListDesigner.DataSource = _currentDataSource.ToString();

                    if (_cmbDataMember.IsSet())
                    {
                        objectListDesigner.DataMember = (String)_cmbDataMember.SelectedItem;
                    }
                    else
                    {
                        objectListDesigner.DataMember = String.Empty;
                    }
                }

                objectListDesigner.OnDataSourceChanged();
            }

            try
            {
                int itemCount = 0;

                if (_txtItemCount.Text.Length != 0)
                {
                    itemCount = Int32.Parse(_txtItemCount.Text, CultureInfo.InvariantCulture);
                }
                objectList.ItemCount = itemCount;
            }
            catch (Exception)
            {
                _txtItemCount.Text = objectList.ItemCount.ToString();
            }

            try
            {
                int itemsPerPage = 0;

                if (_txtItemsPerPage.Text.Length != 0)
                {
                    itemsPerPage = Int32.Parse(_txtItemsPerPage.Text, CultureInfo.InvariantCulture);
                }
                objectList.ItemsPerPage = itemsPerPage;
            }
            catch (Exception)
            {
                _txtItemsPerPage.Text = objectList.ItemsPerPage.ToString();
            }

            objectList.BackCommandText    = _txtBackCommandText.Text;
            objectList.DetailsCommandText = _txtDetailsCommandText.Text;
            objectList.MoreText           = _txtMoreText.Text;

            TypeDescriptor.Refresh(objectList);
        }
コード例 #17
0
        /// <summary>
        ///    <para>
        ///       Persists the properties of a tag.
        ///    </para>
        /// </summary>
        /// <param name='sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name=' prefix'>
        ///    The prefix to store.
        /// </param>
        /// <param name=' propDesc'>
        ///    A property descriptor for the tag properties.
        /// </param>
        private static void PersistAttributes(TextWriter sw, object component, string prefix, PropertyDescriptor propDesc)
        {
            PropertyDescriptorCollection properties;
            string persistPrefix = String.Empty;
            object value         = component;

            if (propDesc != null)
            {
                value      = propDesc.GetValue(component);
                properties = TypeDescriptor.GetProperties(propDesc.PropertyType,
                                                          new Attribute[] {
                    PersistenceModeAttribute.Attribute
                });
            }
            else
            {
                properties = TypeDescriptor.GetProperties(component,
                                                          new Attribute[] {
                    PersistenceModeAttribute.Attribute
                });
            }

            if (value == null)
            {
                return;
            }

            if (prefix.Length != 0)
            {
                persistPrefix = prefix + "-";
            }

            DataBindingCollection dataBindings = null;
            bool isControl = (component is Control);

            if ((component is IDataBindingsAccessor))
            {
                dataBindings = ((IDataBindingsAccessor)component).DataBindings;
            }

            if (component is DeviceSpecificChoice)
            {
                properties = properties.Sort(new String[] { "Filter" });
            }

            for (int i = 0; i < properties.Count; i++)
            {
                // Skip properties that are hidden to the serializer
                if (properties[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                // Skip design-time only properties such as DefaultModifiers and Name
                DesignOnlyAttribute doAttr = (DesignOnlyAttribute)properties[i].Attributes[typeof(DesignOnlyAttribute)];
                if ((doAttr != null) && doAttr.IsDesignOnly)
                {
                    continue;
                }

                string propName = properties[i].Name;
                Type   propType = properties[i].PropertyType;

                object obj = properties[i].GetValue(value);
                if (obj == null)
                {
                    continue;
                }

                DefaultValueAttribute defValAttr =
                    (DefaultValueAttribute)properties[i].Attributes[typeof(DefaultValueAttribute)];
                if ((defValAttr != null) && (obj.Equals(defValAttr.Value)))
                {
                    continue;
                }

                string persistName = propName;

/* AUI Change 3876 -- Change is taken out because of 4347
 *              if (component is DeviceSpecificChoice && persistName.Equals("Xmlns"))
 *              {
 *                  persistName = "xmlns";
 *              }
 * End of Change */

                if (prefix.Length != 0)
                {
                    persistName = persistPrefix + persistName;
                }

                PropertyDescriptorCollection subProps = null;
                if (properties[i].SerializationVisibility == DesignerSerializationVisibility.Content)
                {
                    subProps = TypeDescriptor.GetProperties(propType);
                }
                if ((subProps == null) || (subProps.Count == 0))
                {
                    string persistValue = null;

                    // TODO: Use consts or have DataBinding store both OM name and persist name
                    DataBinding db = null;
                    if (dataBindings != null)
                    {
                        db = dataBindings[persistName.Replace('.', '-')];
                    }

                    if (db == null)
                    {
                        if (propType.IsEnum)
                        {
                            persistValue = Enum.Format(propType, obj, "G");
                        }
                        else if (propType == typeof(string))
                        {
                            persistValue = HttpUtility.HtmlEncode(obj.ToString());
                        }
                        else
                        {
                            TypeConverter converter = properties[i].Converter;
                            if (converter != null)
                            {
                                persistValue = converter.ConvertToInvariantString(null, obj);
                            }
                            else
                            {
                                persistValue = obj.ToString();
                            }
                            persistValue = HttpUtility.HtmlEncode(persistValue);
                        }

                        if ((persistValue == null) ||
                            (persistValue.Equals("NotSet")) ||
                            (propType.IsArray && (persistValue.Length == 0)))
                        {
                            continue;
                        }

                        sw.Write(" ");
                        sw.Write(persistName);
                        sw.Write("=\"");

                        sw.Write(persistValue);
                        sw.Write("\"");
                    }
                }
                else
                {
/*
 *  This will force all ListDictionary properties with DesignerSerializationVisibility.Content atttribute be
 *  persisted as a series of attributes eg. <PropertyFoo Key1="Value1" Key2="Value2" ... />. The
 *  WebControlPersistor is not able to handle this case and will return undesired results.
 */
// AUI Change to handle DeviceSpecificChoice.Contents
                    if (obj is ListDictionary)
                    {
                        IDictionaryEnumerator enumerator = ((ListDictionary)obj).GetEnumerator();
                        String persistValue = null;

                        while (enumerator.MoveNext())
                        {
                            propName     = enumerator.Key as String;
                            persistValue = enumerator.Value as String;

                            Debug.Assert(propName != null,
                                         "Non-string key in DeviceSpecificChoice Contents.");

                            if ((propName.Length == 0) ||
                                (persistValue == null))
                            {
                                continue;
                            }

                            sw.Write(" ");
                            sw.Write(propName);
                            sw.Write("=\"");

                            HttpUtility.HtmlEncode((String)persistValue, sw);
                            sw.Write("\"");
                        }
                    }
                    else
                    {
// End of AUI Change

                        // there are sub properties, don't persist this object, but
                        // recursively persist the subproperties.
                        PersistAttributes(sw, obj, persistName, null);
                    }
                }
            }

            // Persist all the databindings on this control
            if (isControl)
            {
                PersistDataBindings(sw, (Control)component);

                AttributeCollection expandos = null;
                if (component is WebControl)
                {
                    expandos = ((WebControl)component).Attributes;
                }
                else if (component is HtmlControl)
                {
                    expandos = ((HtmlControl)component).Attributes;
                }
                else if (component is UserControl)
                {
                    expandos = ((UserControl)component).Attributes;
                }

                if (expandos != null)
                {
                    foreach (string key in expandos.Keys)
                    {
                        sw.Write(" ");
                        sw.Write(key);
                        sw.Write("=\"");
                        sw.Write(expandos[key]);
                        sw.Write("\"");
                    }
                }
            }
        }
コード例 #18
0
        /// <include file='doc\WebControlPersister.uex' path='docs/doc[@for="ControlPersister.PersistInnerProperties1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Persists the inner properties of the control.
        ///    </para>
        /// </devdoc>
        public static void PersistInnerProperties(TextWriter sw, object component, IDesignerHost host)
        {
            PropertyDescriptorCollection propDescs = TypeDescriptor.GetProperties(component);

            for (int i = 0; i < propDescs.Count; i++)
            {
                // Only deal with inner attributes that need to be persisted
                if (propDescs[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                PersistenceModeAttribute persistenceMode = (PersistenceModeAttribute)propDescs[i].Attributes[typeof(PersistenceModeAttribute)];
                if (persistenceMode.Mode == PersistenceMode.Attribute)
                {
                    continue;
                }

                if (propDescs[i].PropertyType == typeof(string))
                {
                    // String based property...

                    DataBindingCollection dataBindings = null;
                    if (component is IDataBindingsAccessor)
                    {
                        dataBindings = ((IDataBindingsAccessor)component).DataBindings;
                    }
                    if (dataBindings == null || dataBindings[propDescs[i].Name] == null)
                    {
                        PersistenceMode mode = persistenceMode.Mode;
                        if ((mode == PersistenceMode.InnerDefaultProperty) ||
                            (mode == PersistenceMode.EncodedInnerDefaultProperty))
                        {
                            PersistStringProperty(sw, component, propDescs[i], mode);
                        }
                        else
                        {
                            Debug.Fail("Cannot persist inner string property marked with PersistenceMode.InnerProperty");
                        }
                    }
                }
                else if (typeof(ICollection).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Collection based property...
                    if ((persistenceMode.Mode == PersistenceMode.InnerProperty) ||
                        (persistenceMode.Mode == PersistenceMode.InnerDefaultProperty))
                    {
                        PersistCollectionProperty(sw, component, propDescs[i], persistenceMode.Mode, host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist collection property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty or PersistenceMode.InnerDefaultProperty");
                    }
                }
                else if (typeof(ITemplate).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Template based property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistTemplateProperty(sw, component, propDescs[i]);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist template property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
                else
                {
                    // Other complex property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistComplexProperty(sw, component, propDescs[i], host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist complex property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
            }
        }
コード例 #19
0
        /// <summary>
        ///   Saves the component loaded into the page.
        /// </summary>
        /// <seealso cref="System.Windows.Forms.Design.ComponentEditorPage"/>
        protected override void SaveComponent()
        {
            String        dataTextField  = String.Empty;
            String        dataValueField = String.Empty;
            IListDesigner listDesigner   = (IListDesigner)GetBaseDesigner();

            if (_dataTextFieldCombo.IsSet())
            {
                dataTextField = (String)_dataTextFieldCombo.SelectedItem;
            }
            if (_dataValueFieldCombo.IsSet())
            {
                dataValueField = (String)_dataValueFieldCombo.SelectedItem;
            }
            listDesigner.DataTextField  = dataTextField;
            listDesigner.DataValueField = dataValueField;

            if (_dataSourceDirty)
            {
                // save the datasource as a binding on the control
                DataBindingCollection dataBindings = ((HtmlControlDesigner)listDesigner).DataBindings;

                if (_currentDataSource == null)
                {
                    listDesigner.DataSource = String.Empty;
                    listDesigner.DataMember = String.Empty;
                }
                else
                {
                    listDesigner.DataSource = _currentDataSource.ToString();
                    if (_dataMemberCombo.IsSet())
                    {
                        listDesigner.DataMember = (String)_dataMemberCombo.SelectedItem;
                    }
                    else
                    {
                        listDesigner.DataMember = String.Empty;
                    }
                }

                listDesigner.OnDataSourceChanged();
            }

            if (_isBaseControlList)
            {
                List list = (List)GetBaseControl();

                switch (_decorationCombo.SelectedIndex)
                {
                case IDX_DECORATION_NONE:
                    list.Decoration = ListDecoration.None;
                    break;

                case IDX_DECORATION_BULLETED:
                    list.Decoration = ListDecoration.Bulleted;
                    break;

                case IDX_DECORATION_NUMBERED:
                    list.Decoration = ListDecoration.Numbered;
                    break;
                }

                try
                {
                    int itemCount = 0;

                    if (_itemCountTextBox.Text.Length != 0)
                    {
                        itemCount = Int32.Parse(_itemCountTextBox.Text, CultureInfo.InvariantCulture);
                    }
                    list.ItemCount = itemCount;
                }
                catch (Exception)
                {
                    _itemCountTextBox.Text = list.ItemCount.ToString();
                }

                try
                {
                    int itemsPerPage = 0;

                    if (_itemsPerPageTextBox.Text.Length != 0)
                    {
                        itemsPerPage = Int32.Parse(_itemsPerPageTextBox.Text, CultureInfo.InvariantCulture);
                    }
                    list.ItemsPerPage = itemsPerPage;
                }
                catch (Exception)
                {
                    _itemsPerPageTextBox.Text = list.ItemsPerPage.ToString();
                }

                TypeDescriptor.Refresh(list);
            }
            else
            {
                // BUGBUG: handle case where entry is "000" if we decide to disallow this.
                SelectionList selectionList = (SelectionList)GetBaseControl();

                switch (_selectTypeCombo.SelectedIndex)
                {
                case IDX_SELECTTYPE_DROPDOWN:
                    selectionList.SelectType = ListSelectType.DropDown;
                    break;

                case IDX_SELECTTYPE_LISTBOX:
                    selectionList.SelectType = ListSelectType.ListBox;
                    break;

                case IDX_SELECTTYPE_RADIO:
                    selectionList.SelectType = ListSelectType.Radio;
                    break;

                case IDX_SELECTTYPE_MULTISELECTLISTBOX:
                    selectionList.SelectType = ListSelectType.MultiSelectListBox;
                    break;

                case IDX_SELECTTYPE_CHECKBOX:
                    selectionList.SelectType = ListSelectType.CheckBox;
                    break;
                }

                try
                {
                    int rows = 4;

                    if (_rowsTextBox.Text.Length != 0)
                    {
                        rows = Int32.Parse(_rowsTextBox.Text, CultureInfo.InvariantCulture);
                    }
                    selectionList.Rows = rows;
                }
                catch (Exception)
                {
                    _rowsTextBox.Text = selectionList.Rows.ToString();
                }

                TypeDescriptor.Refresh(selectionList);
            }
        }
コード例 #20
0
    protected void PropertyChanged(string propName)
    {
        IControlDesignerTag myHtmlControlDesignBehavior = this.Tag;

        DataBindingCollection myDataBindingCollection;
        DataBinding           myDataBinding1, myDataBinding2;
        String myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2;

        string[] removedBindings1, removedBindings2;
        Int32    temp;

        if (myHtmlControlDesignBehavior == null)
        {
            return;
        }
        // Use the DataBindingCollection constructor to
        // create the myDataBindingCollection1 object.
        // Then set this object equal to the
        // DataBindings property of the control created
        // by this custom designer.
        DataBindingCollection myDataBindingCollection1 = new DataBindingCollection();

        myDataBindingCollection1 = myDataBindingCollection = DataBindings;
        if (myDataBindingCollection.Contains(propName))
        {
            myDataBinding1   = myDataBindingCollection[propName];
            myStringReplace1 = propName.Replace(".", "-");
            if (myDataBinding1 == null)
            {
                myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1);
                return;
            }
            // DataBinding is not null.
            myDataBindingExpression1 = String.Concat("<%#", myDataBinding1.Expression, "%>");
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1);
            int index = myStringReplace1.IndexOf("-");
        }
        else
        {
            // Use the DataBindingCollection.RemovedBindings
            // property to set the value of the removedBindings
            // arrays.
            removedBindings2 = removedBindings1 = DataBindings.RemovedBindings;
            temp             = 0;
            while (removedBindings2.Length > temp)
            {
                removedBinding             = removedBindings2[temp];
                removedBindingAfterReplace = removedBinding.Replace('.', '-');
                myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace);
                temp = temp + 1;
            }
        }
        // Use the DataBindingCollection.GetEnumerator method
        // to iterate through the myDataBindingCollection object
        // and write the PropertyName, PropertyType, and Expression
        // properties to a file for each DataBinding object
        // in the MyDataBindingCollection object.
        myDataBindingCollection = DataBindings;
        IEnumerator myEnumerator = myDataBindingCollection.GetEnumerator();

        while (myEnumerator.MoveNext())
        {
            myDataBinding2 = (DataBinding)myEnumerator.Current;
            String dataBindingOutput1, dataBindingOutput2, dataBindingOutput3;
            dataBindingOutput1 = String.Concat("The property name is ", myDataBinding2.PropertyName);
            dataBindingOutput2 = String.Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1);
            dataBindingOutput3 = String.Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2);
            WriteToFile(dataBindingOutput3);

            myDataBindingExpression2 = String.Concat("<%#", myDataBinding2.Expression, "%>");
            myStringReplace2         = myDataBinding2.PropertyName.Replace(".", "-");
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2);
            int index = myStringReplace2.IndexOf('-');
        }    // while loop ends
    }