[GcSpreadGrid] データ検証のエラー時に表示されるアイコンやツールチップのスタイルを変更する方法

文書番号 : 85093     文書種別 : 使用方法     登録日 : 2020/05/21     最終更新日 : 2020/05/21
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
データ検証のエラー時に表示されるアイコンやツールチップは、ValidationErrorIndicatorクラスにより定義されます。
これをカスタマイズするにはXAMLコードにて、ValidationErrorIndicatorクラスのControlTemplateおよびStyleを変更します。

◎サンプルコード(XAML)
<!-- 以下の名前空間を追加する必要があります。 -->
<!-- xmlns:sg="http://schemas.grapecity.com/windows/spreadgrid/2012" -->
<!-- xmlns:system="clr-namespace:System;assembly=mscorlib" -->

<Window.Resources>
    <ControlTemplate x:Key="ValidationToolTipTemplate" TargetType="ToolTip">
        <Grid x:Name="Root" Margin="5,0" Opacity="0" RenderTransformOrigin="0,0">
            <Grid.RenderTransform>
                <TranslateTransform x:Name="xform" X="-25"/>
            </Grid.RenderTransform>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="OpenStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition GeneratedDuration="0"/>
                        <VisualTransition GeneratedDuration="0:0:0.2" To="Open">
                            <Storyboard>
                                <DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="xform">
                                    <DoubleAnimation.EasingFunction>
                                        <BackEase Amplitude=".3" EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation Duration="0:0:0.2" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                            </Storyboard>
                        </VisualTransition>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Closed">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Open">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="xform"/>
                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border Background="#052A2E31" CornerRadius="5" Margin="4,4,-4,-4"/>
            <Border Background="#152A2E31" CornerRadius="4" Margin="3,3,-3,-3"/>
            <Border Background="#252A2E31" CornerRadius="3" Margin="2,2,-2,-2"/>
            <Border Background="#352A2E31" CornerRadius="2" Margin="1,1,-1,-1"/>
            <Border Background="#FFDC000C" CornerRadius="2"/>
            <Border CornerRadius="2">
                <ContentPresenter/>
            </Border>
        </Grid>
    </ControlTemplate>

    <Style TargetType="sg:ValidationErrorIndicator">
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sg:ValidationErrorIndicator">
                    <Grid x:Name="Root">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="EditorValidationStates">
                                <VisualState x:Name="ValidEditor">
                                </VisualState>
                                <VisualState x:Name="InvalidUnfocusedEditor">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="validationErrorElementBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocusedEditor">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="validationErrorElementBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" Storyboard.TargetName="validationTooltip">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <system:Boolean>True</system:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="validationErrorElementBorder" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="1" Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip" 
      DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                 Margin="-2,0,0,0"
                                 Placement="Right"
                                 PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                 Template="{StaticResource ValidationToolTipTemplate}">
                                    <TextBlock Foreground="White" FontSize="30" MaxWidth="250" Margin="8,4,8,4" TextWrapping="Wrap"
                                       Text="{Binding ValidationErrors[0].ErrorContent}" UseLayoutRounding="false"/>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#FFDC000C" Height="20" Width="20" CornerRadius="10">
                                <TextBlock Foreground="White" FontWeight="Bold" TextAlignment="Center" VerticalAlignment="Center" Text="i"/>
                            </Border>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>