Click here to Skip to main content
14,766,562 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am attempting to use a Data Trigger in WPF, that will only fire when the Working Status is either "Working" or "Working - Non Driver". As it stands now, the foreground is displaying red for all statuses, it is not hitting the boolean in the ViewModel. I suspect the issue is that the string of text is not being read, therefore the XAML is not differentiating between the different Working Statuses. Any ideas would be appreciated.

What I have tried:

<pre>  <TextBlock.Style>
                        <Style TargetType= "TextBlock">
                            <Setter Property="Foreground" Value="Red" />
                                <DataTrigger Binding="{Binding IsWorkingStatus}" Value="False">
                                    <Setter Property="Text" Value="True" />

public Boolean HRStatus { get; set; }

public Boolean IsWorkingStatus
            return HRStatus.ToString().Equals("Working") || HRStatus.ToString().Equals("Working - Non Driver");

George Swan 5-Oct-20 14:03pm
Looks like you are calling ToString() on a bool, doing that will only return either "True" or "False"
v3rd16r15 5-Oct-20 14:08pm
ahhhh just noticed that also. Thank you George, will take a look at that.
George Swan 5-Oct-20 17:20pm
If you are binding to IsWorkingStatus, the property needs to have a setter and to call OnPropertyChanged() in order to inform the view that the value of the property has changed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900