dependency-properties

What is the relationship between INotifyPropertyChanged and DependencyProperty?

I'm building a simple UserControl example with DependencyProperties so that the properties of the control can be changed in XAML (code below). But of course in my application I don't want this control to have tightly-coupled code-behind, but instead the user control will be a view called "DataTypeWholeNumberView" and it will have its ow...

How can I access DependencyProperty values from my code-behind constructor?

I have a UserControl called SmartForm which has a DependencyProperty called Status. In my Window1.xaml, I have the element <local:SmartForm Status="Ready"/>. I would think then in the constructor of the SmartForm object, that Status would equal "Ready" but instead it equals null. Why is then the value of the Status property NULL in th...

DependencyProperty.Register() or .RegisterAttached()

What's the difference between the two, when should RegisterAttached() be used instead of .Register()? ...

WPF - Compilation error: Tags of type 'PropertyArrayStart' are not supported in template sections

Ordinarily I wouldn't just post an error message on SO, but after a Google search only found one hit, I thought I'd at least open the floor for this error here on SO. I have a custom control called Sparkline with a dependency property called Values of type unit[]. Here's an example where I use it in a DataTemplate: <DataTemplate DataT...

WPF TextBlock Binding to DependencyProperty

Hi, I have what I believe to be about one of the most simple cases of attempting to bind a view to a dependencyproperty in the view model. It seems that the initial changes are reflected in the view but other changes to the DP do not update the view's TextBlock. I'm probably just missing something simple but I just can't see what it is. ...

WPF - IsEnabled Binding to DependencyProperty not working properly

I have a dependency property defined in my window as below: public static readonly DependencyProperty IsGenericUserProperty = DependencyProperty.Register("IsGenericUser", typeof (bool), typeof (MainWindow)); public bool IsGenericUser { get { return (bool) GetValue(IsGenericUserProperty); } set { SetValue(IsGenericUserProperty, v...

Dependency Properties and Data Context in Silverlight 3

Hello, I am working with Silverlight 3 beta, and am having an issue. I have a page that has a user control that I worte on it. The user control has a dependency property on it. If the user control does not define a data context (hence using the parent's data context), all works well. But if the user control has its own data context, the...

DependencyProperties where the value is not stored locally

I'm a little confused on creating a DependencyProperty for properties that depend on external sources. For example, in an ultrasound application I'm writing, I currently have the following in a Managed C++ wrapper (translated to C# for simplicity on here, implementing INotifyPropertyChanged): public int Gain { get { return ultrasoun...

WPF: animate a custom dependency property?

Hi everyone, Let's say that I've defined a dependency like this: public class MySampleClass {public static DependencyProperty MyDoubleProperty = DependencyProperty.Register("MyDouble", typeof(double), typeof(MySampleClass)); public double MyDouble { get { return (double)GetValue(MyDoubleProp...

Trying to change a CroppedBitmap's SourceRect at runtime

When I try to change a CroppedBitmap's SourceRect property at runtime, nothing happens. There's no error, and the property value doesn't actually get changed. I'm trying to do sprite animation. I have a BitmapSource that contains a spritesheet, which is a single bitmap containing a grid of different poses for the sprite. Then I have a C...

Syncronously populating DependencyProperties of a custom control in Silverlight

I have a Silverlight custom control with two properties; Text and Id. I have created DependencyProperties for these as per the code below. public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(LookupControl), new PropertyMetadata(NotifyPropertyChanged)); public static readonl...

How to get a silverlight dependency property when not on the UI thread?

I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.RegisterAttached("MyProperty", typeof(bool), typeof(MyObject), new PropertyMetadata(new Propert...

How do You Create a Read-Only Dependency Property?

How do you create a read-only dependancy property? What are the best-practices for doing so? Specifically, what's stumping me the most is the fact that there's no implementation of DependencyObject.GetValue() that takes a System.Windows.DependencyPropertyKey as a parameter. System.Windows.DependencyProperty.RegisterReadOnly returns...

wpf trouble using dependency properties in a UserControl

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...

Binding new property on Custom Control to View Model.

Hi there, How do i extend an existing control (ComboBox in my case) to include a new property which i can bind to a property on my view model?? I have a Dependancy Property on the control's class as follows: public class MyComboBox : ComboBox { public static readonly DependencyProperty MyTextProperty = DependencyProperty.R...

Why Would a Dependency-Property Implementation Crash My Application When I Provide a Default Value?

Why would a dependency-property implementation crash my application when I provide a default value? This segment of code is in the class declaration for my UserControl object. Everything works fine - it compiles and runs perfectly. public static System.Windows.DependencyProperty DepProp = System.Windows.DependencyProperty.Regis...

Chaining dependency properties with MVVM

I am looking for a way to expose a property in my ViewModel and have it influenced by two separate controls in my View. In code view, I am trying to do something like this: propdp object MyObject... <MySelector SelectedItem="{Binding MyObject, Mode=TwoWay}" /> <MyEditor DataContext="{Binding MyObject, Mode=TwoWay}" /> The purpose of...

XAML - How Do I Bind an Element of a Derived <UserControl> to an Element of the Base <UserControl>?

How do I bind an element of a derived <UserControl> to an element of the base <UserControl>? I have defined a UserControl called Tile as my base class. This would be an abstract base class, if XAML wouldn't balk when I tried to instantiate an object derived from it ... Anyway, so far Tile only contains a single dependency property:...

Silverlight Validation Dependency Properties

Anyone used SL3 validation when binding to dependency properties rather than notification properties? If so, where did you write your setter validation code? Do you know of any good web examples? Thanks, Mark ...

In Silverlight, can one define min/max values for a DependencyProperty?

For example, I have a dependency property that changes the ScaleTransform of a Canvas, but if it ever goes below zero it throws an error. Sure, I could just force it to zero in the code if that ever happens, but I'd rather use a better method like using a udouble (unsigned double), which doesn't exist in Silverlight or even setting the m...