0

我在 WPF 中重新设置 ProgressBar 时遇到了一点问题。具体来说,无论我做什么,它似乎都将内部指标限制在 99% 左右。我尝试了各种各样的东西,从剪裁到 OpacityMask,但我似乎无法阻止顶部被切断。有什么想法吗?

代码:

    <Style x:Key="BarrelStyle" TargetType="{x:Type ProgressBar}">
        <Setter Property="Value" Value="100" />
        <Setter Property="Orientation" Value="Vertical" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid>
                        <Border CornerRadius="10" BorderThickness="1" Padding="3,3,3,3" x:Name="PART_Track" Background="Blue">
                            <Border x:Name="PART_Indicator" CornerRadius="10" BorderBrush="#FFC06565" BorderThickness="0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
                                <Grid>
                                    <Border x:Name="Indicator_Content" CornerRadius="10" Background="Red" BorderBrush="White" BorderThickness="1"/>
                                    <Border x:Name="Indicator_Gloss" CornerRadius="10" >
                                        <Border.Background>
                                            <LinearGradientBrush EndPoint="1.0,0.5" StartPoint="0.05,0.5">
                                                <GradientStop Color="#75000000" Offset="0"/>
                                                <GradientStop Color="#7EFFFFFF" Offset="0.5"/>
                                                <GradientStop Color="#75000000" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Border.Background>
                                    </Border>
                                </Grid>
                            </Border>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
4

1 回答 1

1

尝试设置最里面的网格Margin="0,4"并设置 "PART_Indicator" Margin="0,0,0,-4"。或者只使用下面的代码:

<Style x:Key="BarrelStyle" TargetType="{x:Type ProgressBar}">
    <Setter Property="Value" Value="100" />
    <Setter Property="Orientation" Value="Vertical" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ProgressBar}">
                <Grid>
                    <Border CornerRadius="10" BorderThickness="1" Padding="3,3,3,3" x:Name="PART_Track" Background="Blue">
                        <Border x:Name="PART_Indicator" CornerRadius="10" BorderBrush="#FFC06565" BorderThickness="0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0,0,0,-4">
                            <Grid Margin="0,4">
                                <Border x:Name="Indicator_Content" CornerRadius="10" Background="Red" BorderBrush="White" BorderThickness="1"/>
                                <Border x:Name="Indicator_Gloss" CornerRadius="10" >
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="1.0,0.5" StartPoint="0.05,0.5">
                                            <GradientStop Color="#75000000" Offset="0"/>
                                            <GradientStop Color="#7EFFFFFF" Offset="0.5"/>
                                            <GradientStop Color="#75000000" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Grid>
                        </Border>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2009-12-30T21:01:10.773 回答