Page 1 of 1

can not trigger focus with Style

Posted: Sat Jan 28, 2017 4:59 pm
by Henrygo
Hi,team

Implementing a custom control with Style(Generic.xaml), however, can not trigger the overriding OnGotFocus and OnLostFocus events. But OnPointerEntered several other events can be triggered.
how to implement OnGotFocus and OnLostFocus events with style?

Thanks.

Code: Select all

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Application1"
    xmlns:vsm="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >


    <!--ImageButton-->
    <Style x:Key="ImageButtonStyle" TargetType="local:ImageButton">
        <Setter Property="Background" Value="#FF1F3B53"/>
        <Setter Property="Foreground" Value="#FF000000"/>
        <Setter Property="FocusBorderBrush" Value="#FFFF8000"/>
        <Setter Property="FocusMargin" Value="0"/>
        <Setter Property="Padding" Value="3,1,3,0"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ImageButton">
                    <Grid x:Name="LayoutRoot" >
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <!--<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="MouseOverVisualElement" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>-->
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <!--<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundShadow" Storyboard.TargetProperty="(Border.BorderThickness)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Thickness>4,4,0,0</Thickness>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="White"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFC8C8C8"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFEDEDED"/>
                                        </ColorAnimationUsingKeyFrames>-->
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <!--<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0.2"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundShadow" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFE9EBEB"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFEBEBEB"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFEBEBEB"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Stroke).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="00:00:00" Value="#FFD2D2D2"/>
                                        </ColorAnimationUsingKeyFrames>-->
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <!--<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>-->
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="DesignModeStates">
                                <VisualState x:Name="NotSelected">
                                    <Storyboard>
                                        <!--<ColorAnimation Storyboard.TargetName="DesignBorder" Storyboard.TargetProperty="(BorderBrush).(SolidBruch.Color)" To="Transparent" Duration="0:0:0.1" />-->
                                       
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <!--<ColorAnimation Storyboard.TargetName="DesignBorder" Storyboard.TargetProperty="(BorderBrush).(SolidBruch.Color)" To="Blue" Duration="0:0:0.1" />-->
                                       
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Movable">
                                    <Storyboard>
                                        <!--<ColorAnimation Storyboard.TargetName="DesignBorder" Storyboard.TargetProperty="(BorderBrush).(SolidBruch.Color)" To="Red" Duration="0:0:0.1" />-->
                                       
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Resizable">
                                    <Storyboard>
                                        <!--<ColorAnimation Storyboard.TargetName="DesignBorder" Storyboard.TargetProperty="(BorderBrush).(SolidBruch.Color)" To="Yellow" Duration="0:0:0.1" />-->
                                       
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Background" CornerRadius="3">
                            <Grid Margin="0" x:Name="grid">
                                <Border x:Name="BackgroundAnimation" Opacity="0" Background="#FF448DCA"/>
                                <Rectangle x:Name="BackgroundGradient" Margin="0" Stroke="#FF95A0AB" StrokeThickness="1">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFD2D2D2" Offset="1"/>
                                            <GradientStop Color="White" Offset="0.5"/>
                                            <GradientStop Color="White"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Border x:Name="BackgroundShadow" Margin="0" BorderBrush="#FF50565C" BorderThickness="0,0,2,2" CornerRadius="3"/>
                            </Grid>
                        </Border>
                        <Image Margin="0,0,0,0" Stretch="Fill" x:Name="BackgroundImage" Source="{TemplateBinding NormalImage}" />
                        <Image x:Name="DisabledImage" IsHitTestVisible="false" Opacity="1"  Stretch="Fill" Source="{TemplateBinding DisabledImage}"/>
                        <Image Margin="0,0,0,0" x:Name="MouseOverImage" Stretch="Fill" Source="{TemplateBinding MouseOverImage}" />
                        <Image Margin="0,0,0,0" x:Name="PressedImage"  Stretch="Fill" Source="{TemplateBinding PressedImage}" />
                        <Rectangle x:Name="MouseOverVisualElement" Margin="0" Fill="#4CFFFFFF" Opacity="0" StrokeThickness="1" Stroke="{TemplateBinding FocusBorderBrush}"/>
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Opacity="1">
                            <!--<ContentPresenter.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </ContentPresenter.RenderTransform>-->
                        </ContentPresenter>
                        <Rectangle x:Name="DisabledVisualElement" Opacity="0" Fill="#FFFFFFFF"/>
                        <Rectangle x:Name="FocusVisualElement" Opacity="0" Fill="{TemplateBinding FocusBackground}" Stroke="{TemplateBinding FocusBorderBrush}" Margin="{TemplateBinding FocusMargin}" StrokeThickness="{TemplateBinding FocusBorderThickness}" Visibility="{TemplateBinding FocusVisibility}" />
                        <Border Name="DesignBorder" Background ="Transparent" BorderBrush="Transparent" BorderThickness="2" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

Re: can not trigger focus with Style

Posted: Sun Jan 29, 2017 4:33 am
by JS-Support @Userware
Hi,

The "FocusStates" group is not available yet. It is on the roadmap for 2017.

Thanks.
Regards,
JS-Support

Re: can not trigger focus with Style

Posted: Sun Feb 05, 2017 10:34 pm
by Darncat
JS-Support wrote:Hi,

The successful D-Bal Max group is not available yet. It is on the roadmap for 2017.

Thanks.
Regards,
JS-Support


Good to hear!