Skip to content

The ProgressBar's style leaks to its inherited control. #11292

@orrest

Description

@orrest

Description

The implementation here:

demo source code

public class ProgressMask : ProgressBar
{
// ...
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:Tests.Wpf.Controls">

    <Style TargetType="{x:Type controls:ProgressMask}">
        <Setter Property="IsIndeterminate" Value="True" />
        <Setter Property="ProgressBarWidth" Value="280" />
        <Setter Property="ProgressBarHeight" Value="10" />
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="1,0" EndPoint="0,1">
                    <GradientStop Offset="0.0" Color="#B09c9591" />
                    <GradientStop Offset="1.0" Color="#20a89d94" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ProgressMask}">
                    <Border Background="{TemplateBinding Background}">
                        <Grid>
                            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                                <TextBlock Text="{TemplateBinding Caption}" />
                                <ProgressBar Width="{TemplateBinding ProgressBarWidth}"
                                             Height="{TemplateBinding ProgressBarHeight}"
                                             IsIndeterminate="{TemplateBinding IsIndeterminate}" />
                            </StackPanel>
                            <Button Margin="5"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Bottom"
                                    Background="Transparent"
                                    Command="{TemplateBinding CancelCommand}"
                                    Content="{TemplateBinding CancellationText}" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

Reproduction Steps

demo source code

Expected behavior

The ProgressMask.xaml doesn't inherit from ProgrssBar.xaml,
so the TextBlock foreground in the ProgressMask.xaml should be normal black, not the progressbar green foreground.

Actual behavior

The TextBlock foreground in the ProgressMask.xaml is progress's green foreground.

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions