dependency-properties

If we can't bind a MouseBinding's Command, what are we supposed to do?

删除回忆录丶 提交于 2019-12-01 04:11:03
问题 I would love to be able to use a regular MouseBinding to capture a CTRL-Click event on my TextBlock . Unfortunately the Command property is not a dependency property and I'm using MVVM, so I can't bind it to my viewmodel. How could Microsoft have left out this basic functionality? Are there no easy ways to detect CTRL-Clicks and bind them to a command in my viewmodel? 回答1: You could always take a look at using Attached Command Behaviours. 回答2: Originally I believe I was referring to the use

How to create a Dependency property on an existing control?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 04:08:31
I have been reading on Dependency properties for a few days and understand how they retrieve the value rather than to set/get them as in CLR properties. Feel free to correct me if I am wrong. From my understanding all WPF controls like a TextBlock, Button etc that derive from DependencyObject would also contain dependency properties to store their values, instead of using CLR properties. This has the advantage of overriding local values in case animations are used, or inherit values if no local value is set at all etc. I am now trying to come up with some samples to create and use my own dp. 1

wpf trouble using dependency properties in a UserControl

旧巷老猫 提交于 2019-12-01 03:52:09
I made a UserControl that is meant to be updated once every few seconds with data from a serial port. This UserControl should be very simple, consisting of a Label for a field name, and another Label containing the field value. I say that it should be simple, but it doesn't work. It does not update at all, and doesn't even display the field name. Below is the code: public partial class LabeledField : UserControl { public LabeledField() { InitializeComponent(); } public string fieldName { get { return fieldNameLabel.Content.ToString(); } set { fieldNameLabel.Content = value; } } public string

Getting 'this' pointer inside dependency property changed callback

浪子不回头ぞ 提交于 2019-12-01 03:07:28
I have the following dependency property inside a class: class FooHolder { public static DependencyProperty CurrentFooProperty = DependencyProperty.Register( "CurrentFoo", typeof(Foo), typeof(FooHandler), new PropertyMetadata(OnCurrentFooChanged)); private static void OnCurrentFooChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FooHolder holder = (FooHolder) d.Property.Owner; // <- something like this // do stuff with holder } } I need to be able to retrieve a reference to the class instance in which the changed property belongs. This is since FooHolder has some event

How to create a Dependency property on an existing control?

心不动则不痛 提交于 2019-12-01 01:40:13
问题 I have been reading on Dependency properties for a few days and understand how they retrieve the value rather than to set/get them as in CLR properties. Feel free to correct me if I am wrong. From my understanding all WPF controls like a TextBlock, Button etc that derive from DependencyObject would also contain dependency properties to store their values, instead of using CLR properties. This has the advantage of overriding local values in case animations are used, or inherit values if no

wpf trouble using dependency properties in a UserControl

99封情书 提交于 2019-12-01 01:25:09
问题 I made a UserControl that is meant to be updated once every few seconds with data from a serial port. This UserControl should be very simple, consisting of a Label for a field name, and another Label containing the field value. I say that it should be simple, but it doesn't work. It does not update at all, and doesn't even display the field name. Below is the code: public partial class LabeledField : UserControl { public LabeledField() { InitializeComponent(); } public string fieldName { get

What is the need for Coercing a Dependency Property?

拜拜、爱过 提交于 2019-12-01 00:24:29
问题 I saw an example where there were 2 dependency properties: public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register("CurrentReading", typeof(double), typeof(Gauge), new FrameworkPropertyMetadata(Double.NaN, FrameworkPropertyMetadataOptions.None, new PropertyChangedCallback(OnCurrentReadingChanged), new CoerceValueCallback(CoerceCurrentReading) ), new ValidateValueCallback(IsValidReading) ); and public static readonly DependencyProperty MinReadingProperty

Getting 'this' pointer inside dependency property changed callback

别等时光非礼了梦想. 提交于 2019-11-30 23:06:44
问题 I have the following dependency property inside a class: class FooHolder { public static DependencyProperty CurrentFooProperty = DependencyProperty.Register( "CurrentFoo", typeof(Foo), typeof(FooHandler), new PropertyMetadata(OnCurrentFooChanged)); private static void OnCurrentFooChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FooHolder holder = (FooHolder) d.Property.Owner; // <- something like this // do stuff with holder } } I need to be able to retrieve a reference to

Template Binding for Custom Attached Property

冷暖自知 提交于 2019-11-30 22:46:20
I am trying to use an Image in Button Control which animates on Hover and Pressed state by showing different images. Accordingly, I have defined 3 attached properties for the Button Control as given below. public class ButtonExtensions : DependencyObject { public static DependencyProperty ImageSourceProperty = ... public static DependencyProperty ImageHoverSourceProperty = ... public static DependencyProperty ImagePressedSourceProperty = DependencyProperty.RegisterAttached("ImagePressedSource", typeof(string), typeof(ButtonExtensions)); public static string GetImagePressedSource(Button target)

How to Expose a DependencyProperty of a Control nested in a UserControl?

可紊 提交于 2019-11-30 21:49:52
I'm trying to bind an Image down from a Window into a UserControl 'Display' thats inside a UserControl 'DisplayHandler'. Display has a DependancyProperty 'DisplayImage'. This is Similar to this , but their answers didn't help with my problem. DisplayHandler also should have the Property 'DisplayImage' and pass down the Binding to Display. But Visual Studio doesn't allow me to register a DependancyProperty with the same name twice. So I tried to not register it twice but only to reuse it: window <my:DisplayHandler DisplayImage= "{Binding ElementName=ImageList, Path=SelectedItem.Image}" />