开发者

Silverlight RadGridView change TextBox background

开发者 https://www.devze.com 2023-04-01 00:52 出处:网络
I am facing a small problem using silver light . I have a RadGridView, with four columns. My second columns contains text boxes and the third column contains validation errors. If the third column con

I am facing a small problem using silver light . I have a RadGridView, with four columns. My second columns contains text boxes and the third column contains validation errors. If the third column contains validation errors, i want the second column background to turn red. How can i do this. I have tried binding the text box background colum开发者_开发问答n to a string with the desired color but that does not work. Really stuck here. Any help with be much appreciated.

Regards, Mateen


Assuming your binding is otherwise valid, you cannot change colour by binding to a text string of a colour. The background property is of type Brush.

You need to either bind to a Brush instead, or use a brush/colour converter to return a Brush instead of a Color/string etc.

Try these links for converter examples:

http://forums.silverlight.net/p/20392/70263.aspx

http://forums.silverlight.net/p/20392/70263.aspx


You need a StringToObjectConverter found here. This class has the advantage that it has wider uses that eliminate the need to create a plethora of similar converters.

Further rather than having the bound object have a property called "Background" which tell the UI to "be red". I would be better that the Model had a property called "Status" which is an enum of the possible states the object is in.

Going further and looking at your specific requirement it would be better that your model exposed a boolean IsValid property which a converter could be applied to. See this blog on a generic BoolToValueConverter.

0

精彩评论

暂无评论...
验证码 换一张
取 消