How to use PSD in WPF progressbar?

2019-08-04 09:10发布

问题:

I have a PSD file, I want to use it in WPF as a progressbar. I don't know how to do it.

I read this https://msdn.microsoft.com/en-us/library...

There is written, I have to Choose "Import Adobe Photoshop File..." from the "File" menu

But I have "Blend for Visual Studio 2015", there is not such option.

Do I need to install Expression Studio?

After importing, how to use it as a progressbar and update it when necessary ?

The PSD file's image Link = http://s21.postimg.org/70igirqif/Capture.png Please help, I couldn't get any detailed tutorial in this case, I am completely helpless.

回答1:

Here is a sample ControlTemplate for using an image in a ProgressBar:

<ControlTemplate
    x:Key="ImageProgressBarTemplate"
    TargetType="ProgressBar">    
    <ControlTemplate.Triggers>
        <EventTrigger
            RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard>
                <Storyboard
                    x:Name="str">
                    <RectAnimation
                        x:Name="quatanim"
                        Storyboard.TargetName="imgbrush"
                        Storyboard.TargetProperty="(ImageBrush.Viewport)"
                        From="0,0,36,36"
                        To="36,0,36,36"
                        Duration="0:0:5"
                        AutoReverse="False"
                        RepeatBehavior="Forever" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </ControlTemplate.Triggers>

    <!-- Custom progress bar goes here -->
    <Border
        Name="PART_Track"
        Width="{TemplateBinding Width}"
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}"
        Background="{TemplateBinding Background}"
        Height="{TemplateBinding Height}"
        CornerRadius="0"
        Padding="1.5">

        <Grid>
            <!-- Rounded mask (stretches to fill Grid) -->
            <Border
                Name="mask"
                Background="#EEEEEE"
                CornerRadius="0" />

            <!-- Any content -->

            <Rectangle
                Name="PART_Indicator"
                HorizontalAlignment="Left"
                Height="{TemplateBinding Height}">    
                <Rectangle.OpacityMask>
                    <VisualBrush
                        Visual="{Binding ElementName=mask}" />
                </Rectangle.OpacityMask>    
                <Rectangle.Fill>    
                    <ImageBrush
                        x:Name="imgbrush"
                        ImageSource="/myproject;component/Assets/myimage.png"
                        AlignmentX="Left"
                        Stretch="Fill"
                        TileMode="Tile"
                        AlignmentY="Top"
                        ViewportUnits="Absolute"
                        Viewport="0,0,36,36"
                        ViewboxUnits="RelativeToBoundingBox"
                        Viewbox="0,0,1,1">
                    </ImageBrush>    
                </Rectangle.Fill>    
            </Rectangle>    
        </Grid>    
    </Border>    
</ControlTemplate>

Apply it to a progress bar:

<ProgressBar Template="{StaticResource ImageProgressBarTemplate}"/>