WPF 的PROGRESSBAR绑定

来源:互联网 发布:c语言中求绝对值程序 编辑:程序博客网 时间:2024/06/07 12:16

<DataTemplate x:Key="progressBarTemplate">
<Border Margin="0" Height="20" BorderThickness="1" HorizontalAlignment="Stretch" x:Name="brDemo">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="Black"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Value, ElementName=progressBar}" Value="0">
<Setter Property="BorderBrush" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<ProgressBar Height="19" Margin="0,0,0,0" Maximum="100"
x:Name="progressBar" Padding="2" VerticalAlignment="Top" >
<ProgressBar.Value>
<Binding Path="***" Mode="TwoWay" ></Binding>
</ProgressBar.Value>
<ProgressBar.Tag>
<Binding Path="****Tag" Mode="TwoWay" ></Binding>
</ProgressBar.Tag>
<ProgressBar.Style>
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Foreground" Value="LightGreen"/>
<Style.Triggers>
<Trigger Property="Tag" Value="{x:Null}">
<Setter Property="Foreground" Value="Yellow"/>
</Trigger>
<Trigger Property="Value" Value="100">
<Setter Property="Foreground" Value="LightBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</ProgressBar.Style>
<ProgressBar.Template>
<ControlTemplate>
<StackPanel>
<Rectangle Name="PART_Track" Height="0"/>
<Rectangle Name="PART_Indicator" Height="19" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left"/>
</StackPanel>
</ControlTemplate>
</ProgressBar.Template>
</ProgressBar>
</Border>
</DataTemplate>

原创粉丝点击