How to show Marquee style border around object in xaml C# Windows 8

大憨熊 提交于 2019-12-11 04:50:04

问题


Is there a way to show marquee style border around objects in WinRT?

I see there is stroke style of border,

but I want it to move around the object like the lasso tool border in Photoshop or Paint.

Also I need to decide what should be the color of the gap between two strokes of the dashes.

Thank you.


回答1:


This is what you want, since you want the fill color:

<Page.Resources>
    <Storyboard RepeatBehavior="Forever" x:Name="Test">
        <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" 
                Storyboard.TargetProperty="(Shape.StrokeDashOffset)" 
                Storyboard.TargetName="Marquee1">
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="3.5"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" 
                Storyboard.TargetProperty="(Shape.StrokeDashOffset)" 
                Storyboard.TargetName="Marquee2">
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2.5"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Rectangle x:Name="Marquee1" Height="200" Width="200" 
               Stroke="Red" StrokeThickness="10" StrokeDashArray="0.5 2" 
               StrokeDashOffset="1" StrokeDashCap="Square" />
    <Rectangle x:Name="Marquee2" Height="200" Width="200" 
               Stroke="Green" StrokeThickness="10" StrokeDashArray="0.5 2" 
               StrokeDashOffset="0" StrokeDashCap="Square" />
    <Image Height="175" Width="175" />
</Grid>

Looks like this:

Best of luck!




回答2:


Found a way to get Marquee style border work like in Photoshop:

<Storyboard RepeatBehavior="Forever">
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageToDisplayBorder" Storyboard.TargetProperty="StrokeThickness">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageToDisplayBorder" Storyboard.TargetProperty="Stroke">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PaperDark}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageToDisplayBorder" Storyboard.TargetProperty="StrokeDashArray">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="3, 3"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:0.200" Value="3, 3"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:0.400" Value="3, 3"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageToDisplayBorder" Storyboard.TargetProperty="StrokeDashOffset">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="3"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:0.200" Value="0"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:0.400" Value="3"/>
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>

I still don't have a way to specify the Gap color though



来源:https://stackoverflow.com/questions/19800928/how-to-show-marquee-style-border-around-object-in-xaml-c-sharp-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!