Silverlight BusyIndi​​cator的Ajax风格?

时间:2010-07-13 00:25:06

标签: silverlight coding-style busyindicator

我正在寻找一个示例Style来将Silverlight BusyIndi​​cator的外观更改为更像AJAX应用程序的“旋转轮”外观。

围绕谷歌的圈子会产生一些链接,人们正在创建新的控件来实现相同的目标(我怀疑它们是在BusyIndi​​cator之前预定的)但是如果可能的话,我宁愿给BusyIndi​​cator上皮。

有人告诉我正确的方向吗?

由于

标记

2 个答案:

答案 0 :(得分:3)

我是从Silverlight Toolkit

创建自己的自定义BusyIndicator

以下是您的需求:

  1. 在样式文件中设置System命名空间:

    的xmlns:系统= “CLR-命名空间:系统;装配= mscorlib程序”

  2. 将样式/模板放在样式文件中:

    <ControlTemplate x:Key="AjaxBusyIndicatorControlTemplate" TargetType="toolkit:BusyIndicator">
        <Grid x:Name="ColorLayer">               
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="VisibilityStates">
                    <VisualState x:Name="Hidden">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="busycontent">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="overlay">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Visible">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="busycontent">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="overlay">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="BusyStatusStates">
                    <VisualState x:Name="Idle">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="content">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <System:Boolean>True</System:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Busy">
                        <Storyboard RepeatBehavior="Forever" AutoReverse="False">
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="loader">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="359.999"/>
                            </DoubleAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="content">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <System:Boolean>False</System:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <ContentControl x:Name="content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
            <Rectangle x:Name="overlay" Style="{TemplateBinding OverlayStyle}"/>
            <ContentPresenter x:Name="busycontent">
                <Path x:Name="loader" Height="19" Width="19" Canvas.Left="0.5" Canvas.Top="0.5" Stretch="Fill" UseLayoutRounding="False" Stroke="Black" StrokeThickness="0.2" RenderTransformOrigin="0.5,0.5"
                    Data="M9.5,3 C5.9101491,3 3,5.9101491 3,9.5 C3,13.08985 5.9101491,16 9.5,16 C13.08985,16 16,13.08985 16,9.5 C16,5.9101491 13.08985,3 9.5,3 z M9.5,0 C14.746705,0 19,4.2532949 19,9.5 C19,14.746705 14.746705,19 9.5,19 C4.2532949,19 0,14.746705 0,9.5 C0,4.2532949 4.2532949,0 9.5,0 z">
                    <Path.RenderTransform>
                        <CompositeTransform/>
                    </Path.RenderTransform>
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF0089FF" Offset="0"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
            </ContentPresenter>
        </Grid>
    </ControlTemplate>
    
    <Style x:Key="AjaxBusyIndicator" TargetType="toolkit:BusyIndicator"  >
        <Setter Property="Template" Value="{StaticResource AjaxBusyIndicatorControlTemplate}"/>
    </Style>
    
  3. 在您的XAML中使用它:

  4. <Grid x:Name="LayoutRoot" Background="White">
        <toolkit:BusyIndicator IsBusy="True" Style="{StaticResource AjaxBusyIndicator}">
            <TextBox Text="TEST test test" />
        </toolkit:BusyIndicator>
    </Grid>
    

答案 1 :(得分:1)

确实是一个常见的场景.. Silverlight开发人员通常使用 http://blogs.msdn.com/b/brada/archive/2009/03/20/silverlight-3-activity-control.aspx这种控制。但正如你的要求是让它像AJAX一样我认为这个链接可能会有所帮助: http://chrisa.wordpress.com/2008/10/09/a-wait-indicator-in-silverlight/

以下是有关如何为忙碌指示器自定义数据模板的一些提示: http://www.jeff.wilcox.name/2009/11/busy-indicator-control/

问候。