0

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

4

1 回答 1

5

我引用了提问者的评论。据他说,这解决了他的问题

没关系,我想通了。我在我的 XAML 中设置 Foreground 属性,它将始终根据优先规则覆盖我在触发器中设置的内容。一旦我取出TextBlock标签中的 Foreground 属性定义,一切正常!

于 2017-08-14T14:13:28.597 回答