Esempio n. 1
0
//</SnippetResourceProceduralGet>
        void WrapsAroundDOTCode()
        {
//<SnippetDOTFromSystemType>
            DependencyObjectType dt =
                DependencyObjectType.FromSystemType(typeof(Window));
//</SnippetDOTFromSystemType>
        }
        public void TestCache()
        {
            DependencyObjectType t  = DependencyObjectType.FromSystemType(typeof(TestDepObj));
            DependencyObjectType t2 = DependencyObjectType.FromSystemType(typeof(TestDepObj));

            Assert.AreSame(t, t2);
        }
 protected override void OnApply(DependencyProperty dp, Type targetType)
 {
     doType = DependencyObjectType.FromSystemType(targetType);
     propertyChangedCallbackInternal = PropertyChangedCallback;
     PropertyChangedCallback         = OnPropertyChanged;
     base.OnApply(dp, targetType);
 }
        public void IsInstanceOfType()
        {
            DependencyObjectType t  = DependencyObjectType.FromSystemType(typeof(TestDepObj));
            DependencyObjectType t2 = DependencyObjectType.FromSystemType(typeof(TestSubclass));

            Assert.IsTrue(t.IsInstanceOfType(new TestSubclass()));
            Assert.IsTrue(t2.IsSubclassOf(t));
            Assert.IsFalse(t.IsSubclassOf(t2));
        }
Esempio n. 5
0
        public static void SetDefaultValue <TForClass>(this DependencyProperty property, object value)
            where TForClass : DependencyObject
        {
            if (value == null)
            {
                if (property.PropertyType.IsValueType)
                {
                    throw new ArgumentException("The new default value cannot be null.");
                }
            }
            else
            {
                if (!property.PropertyType.IsInstanceOfType(value))
                {
                    throw new ArgumentException("The new default value is not a valid type.");
                }
            }

            PropertyMetadata newPmd;

            PropertyMetadata pmd = property.GetMetadata(DependencyObjectType.FromSystemType(typeof(TForClass).BaseType ?? typeof(object)));

            if (pmd is FrameworkPropertyMetadata)
            {
                FrameworkPropertyMetadata fpmd = pmd as FrameworkPropertyMetadata;
                newPmd = new FrameworkPropertyMetadata()
                {
                    IsAnimationProhibited      = fpmd.IsAnimationProhibited,
                    DefaultUpdateSourceTrigger = fpmd.DefaultUpdateSourceTrigger,
                    AffectsRender        = fpmd.AffectsRender,
                    AffectsMeasure       = fpmd.AffectsMeasure,
                    AffectsArrange       = fpmd.AffectsArrange,
                    AffectsParentMeasure = fpmd.AffectsParentMeasure,
                    AffectsParentArrange = fpmd.AffectsParentArrange,
                    BindsTwoWayByDefault = fpmd.BindsTwoWayByDefault,
                    Inherits             = fpmd.Inherits,
                    IsNotDataBindable    = fpmd.IsNotDataBindable,
                    Journal = fpmd.Journal,
                    OverridesInheritanceBehavior   = fpmd.OverridesInheritanceBehavior,
                    SubPropertiesDoNotAffectRender = fpmd.SubPropertiesDoNotAffectRender
                };
            }
            else
            {
                newPmd = new PropertyMetadata();
            }

            if (pmd != null)
            {
                newPmd.CoerceValueCallback     = pmd.CoerceValueCallback;
                newPmd.PropertyChangedCallback = pmd.PropertyChangedCallback;
            }

            newPmd.DefaultValue = value;

            property.OverrideMetadata(typeof(TForClass), newPmd);
        }
        public void Accessors()
        {
            DependencyObjectType t = DependencyObjectType.FromSystemType(typeof(TestDepObj));

            Assert.AreEqual("TestDepObj", t.Name);
            Assert.AreEqual(typeof(TestDepObj), t.SystemType);
            Assert.AreEqual(typeof(DependencyObject), t.BaseType.SystemType);
            // we can't test the Id field's value, as it's
            // not guaranteed to be anything in
            // particular.
        }
Esempio n. 7
0
 static AnimatedImage()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes the <see cref="SeriesPoint"/> class.
 /// </summary>
 static SeriesPoint()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes the <see cref="Chart"/> class.
 /// </summary>
 static Chart()
 {
     DefaultStyleKeyProperty.OverrideMetadata(typeof(Chart), new FrameworkPropertyMetadata(typeof(Chart)));
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
        public bool Filter(PropertyDescriptor property)
        {
            if (this.element == null)
            {
                return(true);
            }

            // Filter the 20 stylistic set properties that I've never seen used.
            if (property.Name.Contains("Typography.StylisticSet"))
            {
                return(false);
            }

            AttachedPropertyBrowsableForChildrenAttribute          attachedPropertyForChildren  = (AttachedPropertyBrowsableForChildrenAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForChildrenAttribute)];
            AttachedPropertyBrowsableForTypeAttribute              attachedPropertyForType      = (AttachedPropertyBrowsableForTypeAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForTypeAttribute)];
            AttachedPropertyBrowsableWhenAttributePresentAttribute attachedPropertyForAttribute = (AttachedPropertyBrowsableWhenAttributePresentAttribute)property.Attributes[typeof(AttachedPropertyBrowsableWhenAttributePresentAttribute)];

            if (attachedPropertyForChildren != null)
            {
                DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(property);
                if (dpd == null)
                {
                    return(false);
                }

                FrameworkElement element = this.element;
                do
                {
                    element = element.Parent as FrameworkElement;
                    if (element != null && dpd.DependencyProperty.OwnerType.IsInstanceOfType(element))
                    {
                        return(true);
                    }
                }while (attachedPropertyForChildren.IncludeDescendants && element != null);
                return(false);
            }
            else if (attachedPropertyForType != null)
            {
                // when using [AttachedPropertyBrowsableForType(typeof(IMyInterface))] and IMyInterface is not a DependencyObject, Snoop crashes.
                // see http://snoopwpf.codeplex.com/workitem/6712

                if (attachedPropertyForType.TargetType.IsSubclassOf(typeof(DependencyObject)))
                {
                    DependencyObjectType doType = DependencyObjectType.FromSystemType(attachedPropertyForType.TargetType);
                    if (doType != null && doType.IsInstanceOfType(this.element))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else if (attachedPropertyForAttribute != null)
            {
                Attribute dependentAttribute = TypeDescriptor.GetAttributes(this.target)[attachedPropertyForAttribute.AttributeType];
                if (dependentAttribute != null)
                {
                    return(!dependentAttribute.IsDefaultAttribute());
                }
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
 /// <summary>
 /// Texts the box.
 /// </summary>
 static NumericTextBox()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes the <see cref="LineSeries2D"/> class.
 /// </summary>
 static LineSeries2D()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Esempio n. 13
0
        protected void MouseBtnClicked(object sender, CountedClickEventArgs e)
        {
            //CountedClickEventArgs e = _clickCounter.Args;// BtnArgs;
            DependencyObject obj = e.MouseBtnArgs.OriginalSource as DependencyObject;

            if (obj.DependencyObjectType.IsSubclassOf(DependencyObjectType.FromSystemType(typeof(UIElement))))
            {
                //    if (obj.DependencyObjectType.IsSubclassOf(DependencyObjectType.FromSystemType(typeof(Shape)))) { return; }
            }
            else
            {
                return;
            }


            MouseButtonEventArgs mbe = e.MouseBtnArgs as MouseButtonEventArgs;
            ListBox view             = (e.Sender as ListBox);
            ListRow row = view.SelectedItem as ListRow;
            ListRowClickEventArgs arg = new ListRowClickEventArgs();

            try
            {
                arg.ListObj     = view;
                arg.ListRowItem = view.SelectedItem as ListRow;
                arg.rowIndex    = Rows.IndexOf(arg.ListRowItem);
                arg.colIndex    = (arg.ListRowItem == null) ? -1 : (arg.ListRowItem.IndexOf(e.MouseBtnArgs.OriginalSource as UIElement));
                if (arg.rowIndex < 0 || arg.colIndex < 0)
                {
                    if (ListRow.ActivatedRow != null)
                    {
                        ListRow.DeActivate();
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (row == null)
            {
                return;
            }

            //try
            {
                if (e.Count == 1)
                {
                    if (ActionOnClicked == Actions.CheckBoxChecked)
                    {
                        rowCheckboxClicked(row);
                    }
                    else if (ActionOnClicked == Actions.Modify)
                    {
                        if (_editables[arg.colIndex])
                        {
                            row.setModifyMode(arg.colIndex);
                        }
                    }

                    if (E_ListRowClicked != null)
                    {
                        E_ListRowClicked(e.Sender, arg);
                    }
                }
                else if (e.Count == 2)
                {
                    if (ActionOnDoubleClicked == Actions.CheckBoxChecked)
                    {
                        rowCheckboxClicked(row);
                    }
                    else if (ActionOnDoubleClicked == Actions.Modify)
                    {
                        if (_editables[arg.colIndex])
                        {
                            row.setModifyMode(arg.colIndex);
                        }
                    }

                    if (E_ListRowDoubleClicked != null)
                    {
                        E_ListRowDoubleClicked(e.Sender, arg);
                    }
                }
            }
            //catch (Exception ex)
            {
                //    throw ex;
            }
            BeforeClickedRow = row.Index;
        }
Esempio n. 14
0
        public void ReleaseSelection()
        {
            //try
            {
                foreach (ListRow row in Rows)
                {
                    row.Selected = false;
                }
                IsSelected = false;
                _selectedItems.Clear();

                UIElement aChild = null;
                if (Rows.Count > 0 && Rows[0].Count > 0)
                {
                    aChild = Rows[0][0] as UIElement;
                }
                if (aChild == null)
                {
                    return;
                }
                ListBoxItem item = WpfFinder.getParentFromTemplate(aChild, DependencyObjectType.FromSystemType(typeof(ListBoxItem))) as ListBoxItem;
                if (item == null)
                {
                    return;
                }
                item.IsSelected = false;


                ListBox          view = LogicalTreeHelper.GetParent(item) as ListBox;
                DependencyObject obj  = VisualTreeHelper.GetParent(item);
                while (obj != null)
                {
                    if (obj is ListBox || obj is ListView)
                    {
                        view = obj as ListView;
                        break;
                    }
                    obj = VisualTreeHelper.GetParent(obj);
                }
                if (view == null)
                {
                    return;
                }
                //DataTemplate template = this.ContentTemplateSelector.SelectTemplate(this, this);

                view.SelectionMode = System.Windows.Controls.SelectionMode.Single;
                view.SelectionMode = System.Windows.Controls.SelectionMode.Extended;

                view.SelectedItem = null;
                view.SelectedItems.Clear();
                view.SelectedIndex = -1;
                view.SelectedValue = null;

                foreach (ListRow row in view.Items)
                {
                    row.Selected = false;
                }
                IsSelected = false;
            }
            //catch(Exception e) {
            //    throw e;
            //}
        }
Esempio n. 15
0
        public static bool Filter(object target, PropertyDescriptor property)
        {
            var frameworkElement = target as FrameworkElement;

            if (frameworkElement is null)
            {
                return(true);
            }

            var attachedPropertyForChildren = (AttachedPropertyBrowsableForChildrenAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForChildrenAttribute)];

            if (attachedPropertyForChildren is not null)
            {
                var dpd = DependencyPropertyDescriptor.FromProperty(property);
                if (dpd is null)
                {
                    return(false);
                }

                var currentElement = frameworkElement;
                do
                {
                    currentElement = currentElement.Parent as FrameworkElement;
                    if (currentElement is not null &&
                        dpd.DependencyProperty.OwnerType.IsInstanceOfType(currentElement))
                    {
                        return(true);
                    }
                }while (attachedPropertyForChildren.IncludeDescendants && currentElement is not null);

                return(false);
            }

            var attachedPropertyForType = (AttachedPropertyBrowsableForTypeAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForTypeAttribute)];

            if (attachedPropertyForType is not null)
            {
                // when using [AttachedPropertyBrowsableForType(typeof(IMyInterface))] and IMyInterface is not a DependencyObject, Snoop crashes.
                // see http://snoopwpf.codeplex.com/workitem/6712

                if (typeof(DependencyObject).IsAssignableFrom(attachedPropertyForType.TargetType))
                {
                    var doType = DependencyObjectType.FromSystemType(attachedPropertyForType.TargetType);
                    if (doType is not null &&
                        doType.IsInstanceOfType(frameworkElement))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            var attachedPropertyForAttribute = (AttachedPropertyBrowsableWhenAttributePresentAttribute)property.Attributes[typeof(AttachedPropertyBrowsableWhenAttributePresentAttribute)];

            if (attachedPropertyForAttribute is not null)
            {
                var dependentAttribute = TypeDescriptor.GetAttributes(target)[attachedPropertyForAttribute.AttributeType];
                if (dependentAttribute is not null)
                {
                    return(!dependentAttribute.IsDefaultAttribute());
                }

                return(false);
            }

            return(true);
        }