Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Adding a property to all controls to use for styling

$
0
0

Hi all,

My forms have basically 2 states - view only and read/write.  Some controls may be disabled when they don't apply.

Since I need to indicate when a control is disabled (unavailable/not applicable) as separate from being in Readonly/view mode, I can not use IsEnabled to indicate the state.

Some controls have a ReadOnly property.  Others have focusable, etc.  But none of them have anything that is consistent other than enabled - which I can't use.

I want to add a property to all the controls I might use that I can set to indicate if I am in View or Edit mode.  Then my styles can look at them and use the appropriate colors.

I know I can do this by subclassing each control and adding a dependency property.  While this can work, it can be tedious and prone to error, etc.

I think I can use an attached property, but not sure if this is the right approach or if it is bindable, etc.  My thought is to use something like an extension method, but one that I can bind to a property in my model and then use that value to reference in my style.

Or I may just be going off in some damn fool silly direction when there is a much better way to solve the problem.

I just need a property that is available from any WPF forms control (like IsEnabled) where I can set the value and then use a style trigger to set the controls colors.  Should be simple..... (that's a big "should be"... )

And yes, I know I can use Tag, but I already have used that on a number of occasions - once I have something working, I create a real property and use that instead of tag.  I don't want to lose that option.

BTW, my access to the internet may be spotty over the next few days, so please don't jump to conclusions if I don't respond to your helpful suggestions immediately.

Thanks!


me (and yes, I DO mark correct answers)



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>