0
votes

Good Day,

I have a TextBlock element with a black background and text with a black foreground color. I do not want my users to see the text until a task is completed. Then the text will turn into a greenish color.

My style trigger in xaml looks like:

    <Style x:Key="DataImportCompletedStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Foreground" Value="#FF000000" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsImportCompleted}" Value="True">
                <Setter Property="Foreground" Value="#FF99F999" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

My TextBlock looks like:

        <TextBlock x:Name="ImportStatusMesage"
                   Grid.Row="3"
                   Margin="5,0,5,10"
                   Background="Black"
                   FontSize="18"
                   Foreground="#FF000000"
                   Style="{StaticResource DataImportCompletedStyle}"
                   Text="Data Import Completed" />

And my code behind for the IsImportCompleted boolean property is:

    private bool isImportCompleted;
    public bool IsImportCompleted 
    { 
        get { return isImportCompleted; }
        set
        {
            isImportCompleted = value;
            System.Diagnostics.Debug.WriteLine("Import Process Completed...OnPropertyChanged");
            OnPropertyChanged("IsImportCompleted");
        }
    }

which does implement INotifyPropertyChanged. The task works fine and updates the IsImportCompleted property as I am seeing my message in the Output window, but the text doesn't change color.

I thought by using INotifyProperty that the UI would update itself.

I'm using Snoop and verified that the IsImportCompleted is set to true. But still no text color change.

Any advice,

TIA,

coson

1
are you using the same name for your backing bool variable as for your Property or is that a typo? - Mark Hall
You mean here? Binding="{Binding IsImportCompleted}" - coson
Sorry never mind, looking at your definitions you used lowercase and uppercase I's my eyes saw them as the same. - Mark Hall
Never mind, I figured it out. I'm setting the Foreground property in my xaml which will always override what I set in the trigger based on the precedence rules. Once I took out the Foreground property definition in my TextBlock tag, everything worked! - coson
@coson add your solution as answer and mark it as accept for further reference and for users that may have the same problem as you. - Jehof

1 Answers

5
votes

I am quoting from the comment of the Asker. which according to him, this solved his problem

Never mind, I figured it out. I'm setting the Foreground property in my XAML which will always override what I set in the trigger based on the precedence rules. Once I took out the Foreground property definition in my TextBlock tag, everything worked!