2012-07-06 108 views
1

我想在WPF中實現一個垂直進度條,並且遇到了一些困難。我遵循格雷格D的Vertical progress bar template .net的回答,但它不適合我。我已經嘗試使用外部風格和內聯運氣。這很煩人,因爲它似乎是一個相對簡單的答案。我的XAML;垂直進度條Wpf

<ProgressBar Name="VolumeMeter" Orientation="Vertical" Margin="4,30,0,0" 
Value="50" HorizontalAlignment="Left" VerticalAlignment="Top" Height="300" Width="10"> 
    <ProgressBar.Template> 
    <ControlTemplate> 

      <Border BorderBrush="Green" x:Name="Root" BorderThickness="1"> 
       <Grid Name="PART_Track" Background="Red"> 
        <Rectangle Name="PART_Indicator" Fill="Blue"/> 
       </Grid> 
      </Border> 

      <ControlTemplate.Triggers> 
      <Trigger Property="Orientation" Value="Vertical">//Error Here 

       <!-- Rotate the progressbar so the left edge is the bottom edge --> 
       <Setter TargetName="Root" Property="LayoutTransform"> 
        <Setter.Value> 
         <RotateTransform Angle="270" /> 
        </Setter.Value> 
       </Setter> 

       <Setter TargetName="Root" Property="Width" 
       Value="{Binding RelativeSource={RelativeSource TemplatedParent}, 
Path=Height}"/> 
       <Setter TargetName="Root" Property="Height" 
       Value="{Binding RelativeSource={RelativeSource TemplatedParent}, 
Path=Width}"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

    </ProgressBar.Template> 
</ProgressBar> 

我得到的錯誤是在<Trigger Property="Orientation" Value="Vertical">行,我得到;

無法在類型「System.Windows.Controls.Control」上找到模板屬性'方向'。

回答

6

設置ControlTemplateTargetType

+0

完美,感謝H.B.! – windowskm 2012-07-06 14:32:46

2
<ControlTemplate TargetType="ProgressBar"> 

<Trigger Property="ProgressBar.Orientation" Value="Vertical">