2012-07-06 191 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">