ProgressBar 剪切了值的最顶部

发布于 2024-08-16 13:39:21 字数 2094 浏览 4 评论 0原文

我在 WPF 中重新设计 ProgressBar 时遇到了一个小问题。具体来说,无论我做什么,似乎都会将内部指标限制在 99% 左右。我尝试了各种各样的方法,从剪辑到不透明蒙版,但我似乎无法阻止顶部被切断。有什么想法吗?

代码:

    <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>

I'm having a slight problem with reskinning a ProgressBar in WPF. Specifically, no matter what I do, it seems to clip the inner indicator at about 99%. I've tried all sorts of things, from clipping to OpacityMask, but I can't seem to stop the top from cutting off. Any ideas what's going on here?

Code:

    <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫以 2024-08-23 13:39:21

尝试设置最内部网格的 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>

Try setting inner most Grid's Margin="0,4" and set "PART_Indicator" Margin="0,0,0,-4". Or just use the code below:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文