dependencyobject

Trying to setup a custom DependencyObject. Clearly missing something

我的未来我决定 提交于 2019-12-12 02:43:13
问题 I have the following in a UWP app. Notice that my Element descends from DependencyObject, not from a Control, Panel, etc. But when I call the test method MessWithBindings(), the bindings are not working. The PropertyChanged method does fire, but the PropertyChangedEventHandler is null, so it doesn't do anything. Am I supposed to directly setup the event handler somehow? Or is there another call I'm missing that creates it? Incidentally, I have FrameworkElement versions of the BindWidth

VisualTreeHelper not finding children of DependencyObject, How can I reliably find objects?

青春壹個敷衍的年華 提交于 2019-12-10 12:09:14
问题 I have a UserControl called ZoneContainer . This has a property that which contains a ListBox containing a number of ListItem s. Each ListItem contains a DockPanel . I'm trying to use a the following code to find the children that exist inside ZoneContainer but childrenCount is 0 every time. var parent = this as DependencyObject; // I can see that this is populated. int childrenCount = VisualTreeHelper.GetChildrenCount(parent); Is there another way to find a specific child object inside a

WPF custom DependencyProperty notify changes

蓝咒 提交于 2019-12-09 16:13:43
问题 I have a class called MyComponent and it has a DependencyProperty caled BackgroundProperty. public class MyComponent { public MyBackground Background { get { return (MyBackground)GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register("Background", typeof(MyBackground), typeof(MyComponent), new FrameworkPropertyMetadata(default(MyBackground), new PropertyChangedCallback

Why is this Animatable property being set again?

戏子无情 提交于 2019-12-08 06:15:19
问题 Follow up to this question. Apparently, for some reason after having explicitly set the Parent.Child property ( either inside the constructor or explicitly outside of the constructor ), when I set the Child.Trigger property of the Parent.Child object, the Parent.Child object is being set yet again. This can be observed by breaking on the _OnChildChanged method defined within the static constructor. On the second instance of it being called, you can see that e.OldValue is not null, and that it

WPF DependencyProperty Validation Binding to the object property

最后都变了- 提交于 2019-12-07 17:59:30
I am trying to create a validation rule for a given control (in this scenario, it is the TextBox). I am not able to obtain a successful Binding to the property of an object, although appropriate steps were taken: ValidationRule and DepedencyProperty are taken advantage of. Kindly find code below. A side note is that "Is Required" in the custom Validation class is always False, unless I explicitly set the value in the XAML (no Binding, as per "Is Ranged" parameter). Any tips and suggestions are appreciated. Thank you in advance :) XAML Code: <TextBox Style="{StaticResource ValidationError}"

Binding to a collection of DependencyObjects in Silverlight 4

橙三吉。 提交于 2019-12-07 17:14:05
问题 As of Silverlight 4 it is possible to data bind against a DependencyObject (instead of a Framework element in previous versions). So far so good, but how do I bind agains a collection of DependencyObjects. The DataContext is not passed from the ObservableCollection to the collection elements, so that the DependencyProperties of the DependencyObjects are never called (neither the changed events). Neither the DependencyObject offers SetBinding or DataContext to initialize the binding manually.

What is a parent freezable? What does this error mean?

我的未来我决定 提交于 2019-12-06 19:14:12
问题 I'm getting this error: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable What does that even mean? Is it in English? Is the parent frozen, or is it just freezable? Any way to make a parent not freezable, if it makes the error go away? What's happening: I have two opengl winforms controls in a WPF app, and so far, everything's been working smoothly (I think). Now, I've added an update so that when one winform control updates the image, the other should

Binding to a collection of DependencyObjects in Silverlight 4

亡梦爱人 提交于 2019-12-05 18:37:58
As of Silverlight 4 it is possible to data bind against a DependencyObject (instead of a Framework element in previous versions). So far so good, but how do I bind agains a collection of DependencyObjects. The DataContext is not passed from the ObservableCollection to the collection elements, so that the DependencyProperties of the DependencyObjects are never called (neither the changed events). Neither the DependencyObject offers SetBinding or DataContext to initialize the binding manually. Thanks for any advice here. depoll To get the DataContext to propagate in this case, the

What is a parent freezable? What does this error mean?

你离开我真会死。 提交于 2019-12-05 01:15:26
I'm getting this error: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable What does that even mean? Is it in English? Is the parent frozen, or is it just freezable? Any way to make a parent not freezable, if it makes the error go away? What's happening: I have two opengl winforms controls in a WPF app, and so far, everything's been working smoothly (I think). Now, I've added an update so that when one winform control updates the image, the other should as well. That actually used to work, and now I'm getting that error. Stepping through the code has the

Improved IValueConverter — MarkupExtension or DependencyObject?

非 Y 不嫁゛ 提交于 2019-11-28 19:41:32
I saw online 2 different approaches to enhancing an IValueConverter. One of them extended a ValueConverter from MarkupExtension, the other from DependencyObject. I can't extend from both, so I'm wondering if any one is better than the other? Deriving from each gives you different kind of power and flexibility: Deriving from MarkupExtension enables you to use the value converter without making it a static resource, as described below: public class DoubleMe : MarkupExtension, IValueConverter { public override object ProvideValue(IServiceProvider serviceProvider) { return this; } public object