How to create a “custom property” in WPF Style using pure WPF (no code-behind)?

The "No Code Behind" rule in MVVM is for keeping the View and the ViewModel completely separate, and should not be used for view-specific code such as DependencyProperties. Its like saying "Build a house out of these square blocks, but I want a rounded roof and you can't create your own building blocks". The whole point of DependencyProperties is to create additional Properties for your Views that don't already exist.

Up vote 0 down vote favorite share g+ share fb share tw.

Folks I am working in UI de wpf xaml styles dependency-properties link|improve this question edited Aug 16 '11 at 5:41Dave Clemmer1,77331030 asked Jul 25 '11 at 15:06heltonbiker1,046214 93% accept rate.

The "No Code Behind" rule in MVVM is for keeping the View and the ViewModel completely separate, and should not be used for view-specific code such as DependencyProperties. Its like saying "Build a house out of these square blocks, but I want a rounded roof and you can't create your own building blocks". The whole point of DependencyProperties is to create additional Properties for your Views that don't already exist.

The important bit is that the View doesn't directly reference the ViewModel, and vise versa. In your case, I would either create a DependencyProperty in the Code Behind for your UserControl for EllipseColor, or use something like the Background property of the UserControl and bind my Ellipse fill color to that.

Thanks for your thorough explanation! I actually tried to do this, but how can I bind UserControl Background property to the Ellipse without the UserControl itself becoming that color? And what if UserControl Background is already set to another color?

Quite n00b, I know, but... – heltonbiker Jul 25 '11 at 16:00 @heltonBiker I would only use an existing color property if I knew that color was not going to be used or was going to be overwritten. For example, if your UserControl's first child (the Border) defined a Background color, it would cover up the UserControl's BackgroundColor so it would be safe to use that property for the Ellipse color instead. – Rachel Jul 25 '11 at 16:08.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions