这个xaml代码中的错误是什么

时间:2015-08-02 10:58:41

标签: c# wpf xaml progress-bar

我希望路径由prograssbar填充,但这里正在发生其他事情

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ProgressBar" Height="300" Width="400">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Slider Grid.Row="0" Margin="5" Minimum="0" Maximum="100" Name="slider"/>
        <ProgressBar Grid.Row="1" Margin="5" Minimum="0" Maximum="100" Orientation="Horizontal"
                   Value="{Binding ElementName=slider, Path=Value}" Foreground="#FFD81818" Background="{x:Null}">
            <ProgressBar.Template>
                <ControlTemplate>
                    <Grid Background="{TemplateBinding Background}">
                       <Path Name="PART_Track" Height="26" Canvas.Left="37" Opacity="0.702" Canvas.Top="30" 
                                Stroke="Black" 
                                StrokeThickness="5" 
                                    Data="F1M307.5,21.75C303.765,21.75 300.51,19.701 298.793,16.667 298.793,16.667 242.207,16.667 242.207,16.667 240.49,19.701 237.235,21.75 233.5,21.75 229.765,21.75 226.51,19.701 224.793,16.667 224.793,16.667 168.207,16.667 168.207,16.667 166.49,19.701 163.235,21.75 159.5,21.75 155.765,21.75 152.51,19.701 150.793,16.667 150.793,16.667 94.207,16.667 94.207,16.667 92.49,19.701 89.235,21.75 85.5,21.75 81.765,21.75 78.51,19.701 76.793,16.667 76.793,16.667 20.207,16.667 20.207,16.667 18.49,19.701 15.235,21.75 11.5,21.75 5.977,21.75 1.5,17.273 1.5,11.75 1.5,6.227 5.977,1.75 11.5,1.75 15.167,1.75 18.37,3.724 20.111,6.667 20.111,6.667 76.889,6.667 76.889,6.667 78.63,3.724 81.833,1.75 85.5,1.75 89.167,1.75 92.37,3.724 94.111,6.667 94.111,6.667 150.889,6.667 150.889,6.667 152.63,3.724 155.834,1.75 159.5,1.75 163.167,1.75 166.37,3.724 168.111,6.667 168.111,6.667 224.889,6.667 224.889,6.667 226.63,3.724 229.834,1.75 233.5,1.75 237.167,1.75 240.37,3.724 242.111,6.667 242.111,6.667 298.889,6.667 298.889,6.667 300.63,3.724 303.833,1.75 307.5,1.75 313.023,1.75 317.5,6.227 317.5,11.75 317.5,17.273 313.023,21.75 307.5,21.75z"> 
                        </Path>
                        <Path Name="PART_Indicator" Height="26" Canvas.Left="37" Opacity="0.702" Canvas.Top="30" 
                                Stroke="Black" 
                                StrokeThickness="5" Fill="{TemplateBinding Foreground}"
                                    Data="F1M307.5,21.75C303.765,21.75 300.51,19.701 298.793,16.667 298.793,16.667 242.207,16.667 242.207,16.667 240.49,19.701 237.235,21.75 233.5,21.75 229.765,21.75 226.51,19.701 224.793,16.667 224.793,16.667 168.207,16.667 168.207,16.667 166.49,19.701 163.235,21.75 159.5,21.75 155.765,21.75 152.51,19.701 150.793,16.667 150.793,16.667 94.207,16.667 94.207,16.667 92.49,19.701 89.235,21.75 85.5,21.75 81.765,21.75 78.51,19.701 76.793,16.667 76.793,16.667 20.207,16.667 20.207,16.667 18.49,19.701 15.235,21.75 11.5,21.75 5.977,21.75 1.5,17.273 1.5,11.75 1.5,6.227 5.977,1.75 11.5,1.75 15.167,1.75 18.37,3.724 20.111,6.667 20.111,6.667 76.889,6.667 76.889,6.667 78.63,3.724 81.833,1.75 85.5,1.75 89.167,1.75 92.37,3.724 94.111,6.667 94.111,6.667 150.889,6.667 150.889,6.667 152.63,3.724 155.834,1.75 159.5,1.75 163.167,1.75 166.37,3.724 168.111,6.667 168.111,6.667 224.889,6.667 224.889,6.667 226.63,3.724 229.834,1.75 233.5,1.75 237.167,1.75 240.37,3.724 242.111,6.667 242.111,6.667 298.889,6.667 298.889,6.667 300.63,3.724 303.833,1.75 307.5,1.75 313.023,1.75 317.5,6.227 317.5,11.75 317.5,17.273 313.023,21.75 307.5,21.75z">
                        </Path>
                    </Grid>
                </ControlTemplate>
            </ProgressBar.Template>
        </ProgressBar>
        <TextBlock Grid.Row="2" Margin="5" Text="{Binding ElementName=slider, Path=Value}"/>
    </Grid> 
</Window>

制作的图片就像 -

enter image description here

但我想简单一点 -

enter image description here

根据进度值。

1 个答案:

答案 0 :(得分:0)

只需将控件模板中的Grid更改为Canvas

<ControlTemplate>
    <Canvas Background="{TemplateBinding Background}">
        <Path Name="PART_Track" Height="26" Canvas.Left="37" Opacity="0.702" Canvas.Top="30" 
                Stroke="Black" 
                StrokeThickness="5" 
                    Data="...">
        </Path>
        <Path Name="PART_Indicator" Height="26" Canvas.Left="37" Opacity="0.702" Canvas.Top="30" 
                Stroke="Black" 
                StrokeThickness="5" Fill="{TemplateBinding Foreground}"
                    Data="...">
        </Path>
    </Canvas>
</ControlTemplate>

Result