好吧,我将自定义进度条或在C#WPF中加载,而不是矩形,它的末尾应具有较小的清晰度。 看起来像这样
完成加载后,清晰度将消失
目前,这是我所做的。
如何实现自定义加载栏?
这是我的代码XAML
<Window x:Class="loadingbarSolution.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="{x:Type ProgressBar}"
TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Border BorderBrush="#D9DCE1" BorderThickness="0" Background="#FF0C0B0B" CornerRadius="0" Padding="0">
<Grid x:Name="PART_Track">
<Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="#FF2BA9FF" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ProgressBar x:Name="IMSIProgressBar"
HorizontalAlignment="Left"
Height="20" Margin="82,136,0,0"
VerticalAlignment="Top"
Width="200"
BorderThickness="1" Background="#FF0C0B0B"/>
</Grid>
</Window>
我该怎么办?
答案 0 :(得分:2)
后退代码:
class MyCustomConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness(0, 0, -(double)value, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
模板:
<ControlTemplate TargetType="ProgressBar">
<ControlTemplate.Resources>
<local:MyCustomConverter x:Key="sttc"/>
</ControlTemplate.Resources>
<Border BorderBrush="#D9DCE1" BorderThickness="0" Background="#FF0C0B0B" CornerRadius="0" Padding="0" ClipToBounds="True">
<Grid x:Name="PART_Track" Margin="{TemplateBinding Height ,Converter={StaticResource sttc}}">
<Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="#FF2BA9FF" RenderTransformOrigin="0,0">
<Rectangle.RenderTransform>
<TransformGroup>
<SkewTransform AngleX="-45"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Border>
</ControlTemplate>
答案 1 :(得分:0)
您可以在模板中使用Polygon
:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Border BorderBrush="#D9DCE1" BorderThickness="0" Background="#FF0C0B0B" CornerRadius="0" Padding="0">
<Grid x:Name="PART_Track">
<Grid x:Name="PART_Indicator" HorizontalAlignment="Left" Background="#FF2BA9FF">
<Polygon Points="0,20 20,0 20,20" Stroke="#FF0C0B0B" Fill="#FF0C0B0B" HorizontalAlignment="Right" />
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
无论何时Value == Maximum
,例如使用转换器,您都必须将其隐藏。