Click here to Skip to main content
13,090,730 members (44,517 online)
Click here to Skip to main content

Stats

16.4K views
25 bookmarked
Posted 19 Oct 2009

A Simple Solution to Some Problems with Asynchrony in Silverlight

, 9 Mar 2010
A small, extensible suite of classes that elegantly solve some common problems involving asynchrony and event handling that tend to occur when Silverlight and WCF are used together.
<UserControl x:Class="TaskManagerDemo.Controls.InputDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
   MinWidth="270" MinHeight="80">
    <UserControl.Resources>
        <Style x:Key="DefaultButtonStyle" TargetType="Button">
            <Setter Property="IsEnabled" Value="true" />
            <Setter Property="IsTabStop" Value="true" />
            <Setter Property="MinWidth" Value="5" />
            <Setter Property="MinHeight" Value="5" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="Margin" Value="0" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Cursor" Value="Arrow" />
            <Setter Property="FontSize" Value="11" />
            <Setter Property="Padding" Value="0 0 0 0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid MinHeight="22" Margin="0 0 0 5">
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames
                                                    Storyboard.TargetName="Background"
                                                    Storyboard.TargetProperty="Opacity">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames
                                                    Storyboard.TargetName="Background"
                                                    Storyboard.TargetProperty="Opacity">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Disabled" />
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="FocusStates">
                                    <vsm:VisualState x:Name="Focused" />
                                    <vsm:VisualState x:Name="Unfocused" />
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>

                            <Border BorderBrush="#FFE28437" BorderThickness="1,1,1,1"
                                    CornerRadius="10">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFE28437" />
                                        <GradientStop Color="#FFE28437" Offset="0.61699998378753662" />
                                        <GradientStop Color="#FFF8C69E" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>

                            <Border x:Name="Background" Opacity="0" BorderBrush="#FFFFFFFF"
                                    BorderThickness="1,1,1,1" CornerRadius="10">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFE28437" />
                                        <GradientStop Color="#FFE28437" Offset="0.61699998378753662" />
                                        <GradientStop Color="#FFF8C69E" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>

                            <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                Margin="{TemplateBinding Padding}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--Common resources-->
        <SolidColorBrush x:Key="TextBrush" Color="#FFFFFFFF" />
        <Color x:Key="TextColor">#FFFFFFFF</Color>
        <SolidColorBrush x:Key="NormalBrush" Color="#FFFFFF" />
        <SolidColorBrush x:Key="NormalBorderBrush" Color="#FF333333" />
        <SolidColorBrush x:Key="GlyphBrush" Color="#FFD1D1D1" />

        <!--ScrollBar Style-->
        <Style x:Key="ScrollBarStyle" TargetType="ScrollBar">
            <Setter Property="MinWidth" Value="17" />
            <Setter Property="MinHeight" Value="17" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ScrollBar">
                        <Grid x:Name="Root">
                            <Grid.Resources>
                                <ControlTemplate x:Key="RepeatButtonTemplate" TargetType="RepeatButton">
                                    <Grid x:Name="Root" Background="Transparent">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Root" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="HorizontalIncrementTemplate" TargetType="RepeatButton">
                                    <Grid x:Name="Root">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    <vsm:VisualTransition From="Normal" GeneratedDuration="00:00:00.3000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.5000000" To="Normal" />
                                                    <vsm:VisualTransition From="Pressed" GeneratedDuration="00:00:00.5000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.3000000" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.8" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Path Height="10" Width="9" Stretch="Uniform" Data="F1 M 511.047,352.682L 511.047,342.252L 517.145,347.467L 511.047,352.682 Z " Fill="{StaticResource GlyphBrush}" x:Name="path" />
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="HorizontalDecrementTemplate" TargetType="RepeatButton">
                                    <Grid x:Name="Root">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    <vsm:VisualTransition From="Normal" GeneratedDuration="00:00:00.3000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.5000000" To="Normal" />
                                                    <vsm:VisualTransition From="Pressed" GeneratedDuration="00:00:00.5000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.3000000" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.8" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Path Height="10" Width="9" Stretch="Uniform" Data="F1 M 110.692,342.252L 110.692,352.682L 104.594,347.467L 110.692,342.252 Z " x:Name="path" Fill="{StaticResource GlyphBrush}" />
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="VerticalIncrementTemplate" TargetType="RepeatButton">
                                    <Grid x:Name="Root">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    <vsm:VisualTransition From="Normal" GeneratedDuration="00:00:00.3000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.5000000" To="Normal" />
                                                    <vsm:VisualTransition From="Pressed" GeneratedDuration="00:00:00.5000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.3000000" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Path x:Name="path" Height="10" Width="9" Stretch="Uniform" Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L 531.107,321.943 Z " Fill="{StaticResource GlyphBrush}" />
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="VerticalDecrementTemplate" TargetType="RepeatButton">
                                    <Grid x:Name="Root">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    <vsm:VisualTransition From="Normal" GeneratedDuration="00:00:00.3000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.5000000" To="Normal" />
                                                    <vsm:VisualTransition From="Pressed" GeneratedDuration="00:00:00.5000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.3000000" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Path x:Name="path" Height="10" Width="9" Stretch="Uniform" Data="F1 M 541.537,173.589L 531.107,173.589L 536.322,167.49L 541.537,173.589 Z " Fill="{StaticResource GlyphBrush}" />
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="VerticalThumbTemplate" TargetType="Thumb">
                                    <Grid>
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.7" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.6" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ThumbVisual" Storyboard.TargetProperty="Opacity">
                                                            <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Grid Margin="1,0,1,0" x:Name="ThumbVisual">
                                            <Rectangle x:Name="Background" Fill="{StaticResource GlyphBrush}" StrokeThickness="1" RadiusX="3" RadiusY="4" Stroke="{x:Null}" Margin="4.5,-2,5,-2" />
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                                <ControlTemplate x:Key="HorizontalThumbTemplate" TargetType="Thumb">
                                    <Grid>
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualStateGroup.Transitions>
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    <vsm:VisualTransition From="Normal" GeneratedDuration="00:00:00.3000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.5000000" To="Normal" />
                                                    <vsm:VisualTransition From="Pressed" GeneratedDuration="00:00:00.5000000" To="MouseOver" />
                                                    <vsm:VisualTransition From="MouseOver" GeneratedDuration="00:00:00.3000000" To="Pressed" />
                                                </vsm:VisualStateGroup.Transitions>
                                                <vsm:VisualState x:Name="Normal" />
                                                <vsm:VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.7" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.6" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ThumbVisual" Storyboard.TargetProperty="Opacity">
                                                            <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1" />
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Grid Margin="0,1,0,1" x:Name="ThumbVisual">
                                            <Rectangle x:Name="Background" Fill="{StaticResource GlyphBrush}" StrokeThickness="1" RadiusX="2" RadiusY="2" Stroke="{x:Null}" Margin="-2,3.5,-2,4" />
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </Grid.Resources>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver" />
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="0.5" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Grid x:Name="HorizontalRoot">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Rectangle Grid.ColumnSpan="5" Stroke="#00000000" StrokeThickness="1" RadiusX="1" RadiusY="1" Fill="{StaticResource NormalBrush}" />
                                <RepeatButton Margin="1" x:Name="HorizontalSmallDecrease" Width="16" IsTabStop="False" Template="{StaticResource HorizontalDecrementTemplate}" Grid.Column="0" Interval="50" />
                                <RepeatButton x:Name="HorizontalLargeDecrease" Width="0" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="1" Interval="50" />
                                <Thumb MinWidth="18" x:Name="HorizontalThumb" Width="18" Background="{TemplateBinding Background}" Template="{StaticResource HorizontalThumbTemplate}" Grid.Column="2" />
                                <RepeatButton x:Name="HorizontalLargeIncrease" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="3" Interval="50" />
                                <RepeatButton Margin="1" x:Name="HorizontalSmallIncrease" Width="16" IsTabStop="False" Template="{StaticResource HorizontalIncrementTemplate}" Grid.Column="4" Interval="50" />
                            </Grid>
                            <Grid x:Name="VerticalRoot" Visibility="Collapsed">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Rectangle Grid.RowSpan="5" Stroke="#00000000" StrokeThickness="1" RadiusX="1" RadiusY="1" Fill="{StaticResource NormalBrush}" />
                                <RepeatButton Height="16" Margin="1" x:Name="VerticalSmallDecrease" IsTabStop="False" Template="{StaticResource VerticalDecrementTemplate}" Grid.Row="0" Interval="50" />
                                <RepeatButton Height="0" x:Name="VerticalLargeDecrease" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="1" Interval="50" />
                                <Thumb Height="18" MinHeight="18" x:Name="VerticalThumb" Template="{StaticResource VerticalThumbTemplate}" Grid.Row="2" />
                                <RepeatButton x:Name="VerticalLargeIncrease" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="3" Interval="50" />
                                <RepeatButton Height="16" Margin="1" x:Name="VerticalSmallIncrease" IsTabStop="False" Template="{StaticResource VerticalIncrementTemplate}" Grid.Row="4" Interval="50" />
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--ScrollViewer Style-->
        <Style x:Key="ScrollViewerStyle" TargetType="ScrollViewer">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Top" />
            <Setter Property="VerticalScrollBarVisibility" Value="Visible" />
            <Setter Property="Padding" Value="4" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ScrollViewer">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
                            <Grid Background="{TemplateBinding Background}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ScrollContentPresenter Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}" x:Name="ScrollContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" />
                                <Rectangle Grid.Column="1" Grid.Row="1" Fill="#FFE9EEF4" />
                                <ScrollBar x:Name="VerticalScrollBar" Width="18" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" IsTabStop="False"
                                    Grid.Column="1" Grid.Row="0" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}" Maximum="{TemplateBinding ScrollableHeight}"
                                    Minimum="0" Value="{TemplateBinding VerticalOffset}" Style="{StaticResource ScrollBarStyle}" />
                                <ScrollBar Height="18" x:Name="HorizontalScrollBar" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" IsTabStop="False"
                                    Grid.Column="0" Grid.Row="1" Orientation="Horizontal" ViewportSize="{TemplateBinding ViewportWidth}" Maximum="{TemplateBinding ScrollableWidth}"
                                    Minimum="0" Value="{TemplateBinding HorizontalOffset}" Style="{StaticResource ScrollBarStyle}" />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" Height="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="5" />
            <RowDefinition MaxHeight="350" Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="30" />
            <RowDefinition Height="5" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10" />
            <ColumnDefinition MinWidth="270" />
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <TextBlock Visibility="Collapsed" x:Name="Message" MaxHeight="350" FontSize="12" Margin="0,5,0,0" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="1" Foreground="Black" TextWrapping="Wrap" Text="Data is loading..." />
        <ScrollViewer x:Name="scrollContent" Width="300" Margin="0" Style="{StaticResource ScrollViewerStyle}" HorizontalAlignment="Left"  Grid.Column="1" Grid.Row="1"
            HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0">
            <TextBox x:Name="TextBox" IsReadOnly="True" MaxWidth="290" VerticalAlignment="Stretch" BorderThickness="0" Background="Transparent" TextWrapping="Wrap" AcceptsReturn="true" />
        </ScrollViewer>
        <Grid Margin="10,0,10,0" MinWidth="270" Grid.Row="3" Grid.Column="1">
            <Button x:Name="btnCancel" Content="Cancel" Click="btnCancel_Click" Height="30" HorizontalAlignment="Left"
                Style="{StaticResource DefaultButtonStyle}" MinWidth="80" />
            <Button x:Name="btnOK" Content="OK" Click="btnOK_Click" Height="30" HorizontalAlignment="Right"
                Style="{StaticResource DefaultButtonStyle}" MinWidth="80" />
        </Grid>
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

George Henry 1954
Software Developer (Senior) Concur
United States United States
George Henry has worked as a software developer for more than 20 years. He is currently employed by Concur in Bellevue, Washington, USA.

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 9 Mar 2010
Article Copyright 2009 by George Henry 1954
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid