Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
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:

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




ViewModel
public Boolean HRStatus { get; set; }




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


        }
    }
Posted
Comments
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)



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