当前位置: 代码迷 >> Windows Mobile >> 温度表(ProgressBar)无法工作
  详细解决方案

温度表(ProgressBar)无法工作

热度:387   发布时间:2016-04-25 07:10:28.0
温度计(ProgressBar)无法工作
本帖最后由 LH806732 于 2014-11-08 19:59:22 编辑
使用:
<ProgressBar x:Name="templateProgress" Template="{StaticResource templateThermometer}" Value="60" Minimum="0" Maximum="100"  Orientation="Vertical" Width="30" Height="280" Grid.Column="1"/>



设置Value值没反应!



模板:
<ControlTemplate x:Key="templateThermometer" TargetType="{x:Type ProgressBar}">
        <!-- Define two brushes for the thermometer liquid -->
        <ControlTemplate.Resources>
            <LinearGradientBrush x:Key="brushStem" StartPoint="0 0" EndPoint="1 0">
                <GradientStop Offset="0" Color="Red" />
                <GradientStop Offset="0.3" Color="Pink" />
                <GradientStop Offset="1" Color="Red" />
            </LinearGradientBrush>

            <RadialGradientBrush x:Key="brushBowl"  GradientOrigin="0.3 0.3">
                <GradientStop Offset="0" Color="Pink" />
                <GradientStop Offset="1" Color="Red" />
            </RadialGradientBrush>
        </ControlTemplate.Resources>

        <!-- Two-row Grid divides thermometer into stem and bowl -->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <!-- Second grid divides stem area in three columns -->
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="25*" />
                    <ColumnDefinition Width="50*" />
                    <ColumnDefinition Width="25*" />
                </Grid.ColumnDefinitions>

                <!-- 温度计管管 -->
                <Border Grid.Column="1" BorderBrush="SpringGreen"  BorderThickness="3 3 3 0" CornerRadius="6 6 0 0" >
                    <!-- Track -->
                    <Decorator Name="PART_Track">
                        <!-- 指示进度 -->
                        <Border Name="PART_Indicator" CornerRadius="6 6 0 0" VerticalAlignment="Bottom" Background="{StaticResource brushStem}" >
                        </Border>
                    </Decorator>
                </Border>
            </Grid>

            <!-- 温度计水银槽外边框为一个圆 -->
            <Ellipse Grid.Row="1"  Width="{TemplateBinding Width}"  Height="{TemplateBinding Width}" Stroke="Black" StrokeThickness="3" />

            <Grid Grid.Row="1" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="50*" />
                    <RowDefinition Height="50*" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="25*" />
                    <ColumnDefinition Width="50*" />
                    <ColumnDefinition Width="25*" />
                </Grid.ColumnDefinitions>

                <!-- 温度计管管和水银槽之间的连接处 -->
                <!--
                <Border Grid.Row="0" Grid.Column="1" BorderBrush="RoyalBlue"  BorderThickness="3 0 3 0"  Background="{StaticResource brushStem}" Opacity="0.5"/>
                -->
                <Border Grid.Row="0" Grid.Column="1" BorderBrush="Blue"  BorderThickness="3 0 3 0" Opacity="0.5"/>
            </Grid>

            <!-- 水银槽背景 -->
            <Ellipse Grid.Row="1"  Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Stroke="Transparent" StrokeThickness="6" Fill="{StaticResource brushBowl}" Opacity="0.7"/>

        </Grid>
    </ControlTemplate>

------解决思路----------------------
引用:
Quote: 引用:

ControlTemplate被你改出问题了吧,视觉状态呢,怎么一个没有。


又不是交互控件,没有视觉状态也是允许的吧。

和交互不交互没关系,这控件默认的外观效果是由视觉状态控制的,楼主给删掉了,也看不错楼主这是什么平台(sl还是windowsphone RT)的进度指示器了,被改的面目全非。
------解决思路----------------------
想改的话,先去看看ProgressBar的默认模板吧。
用Blend生成一个就行了。
  相关解决方案