user282807
user282807

Reputation: 925

How to create a dependency property in Silverlight using MVVM?

let say there is a textbox and i want to control the visibility of this control using MVVM, is there a sample on how to do this? First create a dependency property then get it hooked up in the ViewModel. Thanks.

Upvotes: 1

Views: 160

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564393

Typically, you wouldn't need to use a dependency property in this case. Dependency properties really only need to be implemented for things like controls themselves, not for determining behavior. Behavior, such as the visibility of an element, can be handled directly via data binding.

Your ViewModel would just have some property, and you'd bind the TextBox.Visibility property directly to the ViewModel property.

The one "sticky point" is that you often will want to have some type of IValueConverter that will convert from your property type to a Visibility enum.

Upvotes: 3

Related Questions