Binding MVVM backcolor textbox

Markus Freitag 3,786 Reputation points
2020-07-17T06:07:00.027+00:00

Hello,
I need this feature.
Is the textbox empty the backcolor should be 'light red'
Is the textbox string length > 0 empty the backcolor should be 'light green'

Please help me, how I can solve it. Thanks a lot.
12606-binding-backcolor.png

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,720 questions
0 comments No comments
{count} votes

Accepted answer
  1. Markus Freitag 3,786 Reputation points
    2020-07-17T10:11:19.323+00:00

    Thanks,
    yes looks easy.
    Not clear for me is. MyTextBoyStyle?
    Is it a class?
    Where you check the length == 0 then LightPink?
    I think I need code there?

    Can you send more details? Thanks in advance.


2 additional answers

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,316 Reputation points
    2020-07-17T07:13:01.057+00:00

    Hi Markus,
    you can use style. If validator return error Validatio.HasError will be True:

    12812-x.png
    12757-17-07-2020-09-06-57.gif

    1 person found this answer helpful.
    0 comments No comments

  2. DaisyTian-1203 11,621 Reputation points
    2020-07-17T08:52:41.45+00:00

    You can also set the style with DataTrigger for your TextBox and use it like below(similar to your old thread):
    12788-capture.png

    The result is like :

    12832-3.gif

    1 person found this answer helpful.
    0 comments No comments