dependency-properties

WPF: DependencyProperty refusing to work.

I'm trying to register 3 dependency properties on a Window to control it's formatting. I've looked over and over the code but I must be missing something. public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.White)); pu...

What's the difference between a dependency property and an attached property in WPF?

What's the difference between a (custom) dependency property and an attached property in WPF? What are the uses for each? How do the implementations typically differ? ...

Silverlight 2.0: Determine if a dependency property is set before changing it.

I have a dependency property (Foreground) on a custom control which is inheriting from Control. When I am loading the control, I want to see if the user has set the dependency property or if it is using its default value before I set the value for them. The problem is a bit more complicated then that, here it is: The control is in a ...

How can I add a PropertyChangedCallback to a dependency-property of the base class?

I have a class derived from System.Windows.Controls.UserControl, and I need to add a PropertyChangedCallback to the FrameworkElement.Margin dependency-property. How is this accomplished from my C# code? I can't find any good examples of this in MSDN. ...

Adding a UIElementCollection DependencyProperty in Silverlight

I want to add a dependency property to a UserControl that can contain a collection of UIElement objects. You might suggest that I should derive my control from Panel and use the Children property for that, but it is not a suitable solution in my case. I have modified my UserControl like this: public partial class SilverlightControl1 : ...

Is there a *clean* way to make a read-only dependency-property reflect the value of another property?

The code below is my current solution. If it takes you a couple minutes to figure out what this code is doing, I hear ya. This is an ugly mess if ever there was one. I would kill to see an alternative, (but don't let that discourage you from responding... :-). Oh jeez, I even abbreviated it (substantially) by removing the converter...

Is it possible to "cancel" a dependency-property assignment from an IValueConverter, if there was no change in the property value?

I have a data-binding set on a dependency property of a class. I also have an IValueConverter to handle the calculation of this value based on other elements. The context of my question is inside the IValueConverter.Convert method. #1 If the calculated return value is equal to the current property value, can I tell the framework not t...

How can I add logic to an existing dependency-property callback?

I'm trying to add a PropertyChangedCallback to UIElement.RenderTransformOriginProperty. An exception is thrown when I try to override the PropertyMetadata. I have searched MSDN and Google, and all I have been able to come up with is this. DependencyPropertyDescriptor.AddValueChanged is suggested at some point in that post, but that wo...

How can I create a custom *write-only* dependency-property?

I need to know what the procedure is for making a write-only dependency-property. I can see that the DependencyProperty class does not have a special "Register" method for write-only properties, but I have no idea whether the RegisterAttached method may apply to what I am trying to do. This property needs to be a dependency-property, ...

Can I make a dependency property that's read-only?

I need this dependency property to be accessible for read operations only. Outside objects should not be able to assign values to it. ...

Invalid Cast Exception when trying to convert a property of a user control in a binding.

I have a user control that has a textbox. I have tried to expose the texbox's Text property by implementing a DependencyProperty with the same name in the UserControl. Thus: public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), ...

Dependency property in app.xaml.cs

Hello, I am new to WPF and the below question may look silly for many, please pardon me. How can I create a dependency property in app.xaml.cs? Actually, I tried to created it. The below code, public static DependencyProperty TempProperty = DependencyProperty.Register("Temp", typeof(string), typeof(App)); public strin...

Dependency Property dependent on another

How can one register a dependency property whose value is calculated using the value of another dependency property? Because the .NET property wrappers are bypassed by WPF at run-time, one should not include logic in the getters and setters. The solution to that is typically to use PropertyChangedCallbacks. But those are declared stat...

How do I bind to this custom dependency property?

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); } s...

What's the point in setting up dependency properties, when PropertyChangedEventHandler does the job?

Currently I have use the following approach to setup change notification on any of my properties that I bind to in xaml: class MyClass : INotifyPropertyChanged { string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); ...

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

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

Bind to an attached behavior on a Storyboard

I have created an attached dependency property for Storyboards, with the intention of enabling me to call a method on my ViewModel when a Storyboard Completed event fires: public static class StoryboardExtensions { public static ICommand GetCompletedCommand(DependencyObject target) { return (ICommand)target.GetValue(Comp...

Difference among three kinds of dependency properties in .NET Workflow Foundation.

In .NET Workflow Foundation, there are three kinds of dependency proprieties: instance properties, meta properties, and attached properties. Can someone explain what the difference and proper usages are? Thanks. ...

Is there a better way to self reference a type?

I'm finding lately a lot of code smells related to referencing generic classes in C#. My gripes especially apply to those classes which inherit from DependencyObject and contain DependencyProperties. The basic problem is that when declaring a dependency property one generally references the current type which is also known as the owner...

Delayed "rendering" of WPF/Silverlight Dependency Properties?

Is there a way to know the first time a Dependency Property is accessed through XAML binding so I can actually "render" the value of the property when needed? I have an object (class derived from Control) that has several PointCollection Dependency Properties that may contain 100's or 1000's of points. Each property may arrange the poin...