dependency-properties

How do I bind to this custom dependency property?

不打扰是莪最后的温柔 提交于 2019-12-10 11:24:02
问题 I have a DependencyProperty in my custom UserControl that looks like this: public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", typeof(int), typeof(CallBoard), new PropertyMetadata(150)); public int ColumnWidth { get { return (int)GetValue(ColumnWidthProperty); } set { SetValue(ColumnWidthProperty, value); } } In Expression Blend 3, I have this: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:/

WPF bind usercontrol's property to parent's property

可紊 提交于 2019-12-10 01:59:55
问题 I have created a usercontrol, which has 2 dependency properties. I want to bind those dependency properties to the mainViewModel's property, so that whenever something gets changed in the user-control the parent's property gets updated. I tried, binding it normally but it didn't work. How can I bind the user-control's DP to the parent's property. I tried this: UC: <TextBox Name="TextBox" Text="{Binding ElementName=UCName, Path=DP1, Mode=TwoWay}"/> MainWindow: <UCName:UCName Width="330"

DependencyProperty doesn't fire ValueChanged when new value is the same

ε祈祈猫儿з 提交于 2019-12-10 01:30:02
问题 Ok so here's the problem: I wrote a UserControl which receives a new value say like every 100ms and does something with it. It has to handle each new value setter, even if the value didn't change. The UserControl has a few DependencyProperties: public double CurrentValue { get { return (double)GetValue(CurrentValueProperty); } set { SetValue(CurrentValueProperty, value); } } public static readonly DependencyProperty CurrentValueProperty = DependencyProperty.Register("CurrentValue", typeof

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 Dependency property are declared as static readonly?

被刻印的时光 ゝ 提交于 2019-12-09 15:27:20
问题 It is clear to me why dependency property are static and the question still remain on my mind is why we need to use Readonly keyword at the time of declaration of Dependency Property. 回答1: Conceptually a dependency property is something that a dependency object simply has and that does not depend on when you use the property. Just like a CLR property, if you ask does this object have a Total property, you know it cannot be a double now but an int later. As a result, we'd make the dependency

What is a Dependency Property and when is it used? [duplicate]

旧时模样 提交于 2019-12-08 19:16:41
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What is a dependency property? hi guys, I have been browsing through the net to find the definition of a dependency prop, but cannot find the simplest def for this.Can anyone help me with an example? Thanks 回答1: There have already been a number of discussions here itself regarding this.Please go through some. What is a dependency property? What is the Dependency property in WPF Dependency Property In WPF

WPF Custom Control: DependencyProperty never Set (on only 1 of many properties)

时间秒杀一切 提交于 2019-12-08 17:03:40
问题 I have made a custom control called AddressForm , which inherits from Control. The control is used to display the fields for an IAddress object. Originally I made this control in Silverlight, now I am trying to get it working in WPF .net 4.5 The control defines 9 different dependency properties, and all but one is working correctly. Naturally, the one that is not working is the Address object itself! The Control's Address property never receives a value. I put a break-point in the address's

Binding on DependencyProperty of custom User Control not updating on change

二次信任 提交于 2019-12-08 15:13:26
问题 I'm having difficulties with databinding on my custom user control (s). I created an example project to highlight my problem. I'm completely new to WPF and essentially MVVM as well, so bear with me... I created a simple view that uses databinding two ways. The databinding on the built-in control works just fine. My custom control doesn't... I put a breakpoint in the PropertyChangedCallback of my control. It gets hit once on startup, but then never again. Meanwhile, the label I have bound to

Is there something wrong with my dependency property? Content not set with binding

霸气de小男生 提交于 2019-12-08 11:09:13
问题 I wonder if theres something wrong with my dependency property? // In MarkdownEditor.xaml.cs, DataContext for MarkdownEditor.xaml public string TextContent { get { return (string)GetValue(TextContentProperty); } set { SetValue(TextContentProperty, value); } } public static readonly DependencyProperty TextContentProperty = DependencyProperty.Register("TextContent", typeof(string), typeof(MarkdownEditor), new UIPropertyMetadata("")); When TextContent is set in XAML like <me:MarkdownEditor

Cannot convert lambda expression to type 'System.Delegate', Because it is not a delegate type

∥☆過路亽.° 提交于 2019-12-08 09:39:18
问题 I define a dependency Property for my class1, which raise an event. I don't know why it give me this error "Cannot convert lambda expression to type 'System.Delegate'" public static readonly DependencyProperty class1Property = DependencyProperty.Register("class1Property", typeof(Class1), typeof(UserControl1), new PropertyMetadata(null)); public Class1 class1 { get { return Dispatcher.Invoke((() => GetValue(class1Property)))as Class1; } set { Dispatcher.Invoke(new Action(() => { SetValue