1
我正在嘗試爲ProgressBar編寫一個WPF樣式,它將標準欄變成「Progress pie」。爲WPF ProgressBar編寫「Progress Pie」風格
這是我到目前爲止已經試過:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="ProgressPie" TargetType="{x:Type ProgressBar}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid x:Name="TemplateRoot" SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse x:Name="PART_Track"
Fill="{TemplateBinding Background}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
<ed:Arc x:Name="PART_Indicator"
ArcThickness="1"
ArcThicknessUnit="Percent"
Fill="{StaticResource SomeStaticBrush}"
ToolTip="{TemplateBinding Value}"
EndAngle="{TemplateBinding Value}"/>
<ed:Arc x:Name="OuterPieBorder"
ArcThickness="{TemplateBinding BorderThickness}"
ArcThicknessUnit="Pixel"
Stroke="{TemplateBinding BorderBrush}"
StartAngle="0"
EndAngle="360"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
不幸的是我至少有幾個問題:
- 看來的
PART_Indicator
寬度必然的了Value
模板。怎麼來的?我沒有寫任何文件。 - 我找不到一個簡單的方法來定位
PART_Indicator
,使餡餅的中心與PART_Track
的中心重合;有什麼建議麼?
謝謝,在等待答案的同時,我也發現了這一點。總結一下: * PART_Indicator的寬度被模板設置爲Value * PART_Track,顯然沒有任何關係。 *弧形不允許自然指定中心點的位置,以實現自定義形狀是必需的。 – elnigno
你明白了......但我不明白爲什麼這是一個問題......你沒有義務申報PART_Indicator,是嗎? – Olivier
我不確定,我試着重命名它,應用程序仍然會編譯;然而,當我嘗試顯示進度條時,我遇到了崩潰。 – elnigno