开发者

Add Custom Popup for mouseover of Datepicker

开发者 https://www.devze.com 2023-03-19 04:55 出处:网络
I am adding a trigger to a custom Datepicker to trigger a popup textblock. However, when i run the code, i get an unhandled nullreferenceexception.

I am adding a trigger to a custom Datepicker to trigger a popup textblock.

However, when i run the code, i get an unhandled nullreferenceexception.

if i remove the trigger, everything works fine.

<Grid.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="Popup_PrevButton" Property="IsOpen" Value="True" />
        <Setter TargetName="Popup_NextButton" Property="IsOpen" Value="True" />
    </Trigger>
    <Trigger Property="IsMouseOver" Value="False">
        <Setter TargetName="Popup_PrevButton" Property="IsOpen" Value="False" />
        <Setter TargetName="Popup_NextButton" Property="IsOpen" Value="False" />
    </Trigger>
</Grid.Triggers>

I have tried placing the trigger in the PART_Button and ControlTemplate but nothing works.

The popup code is placed right after the PART_Popup a开发者_JS百科nd is as follows:

<Popup x:Name="Popup_PrevButton"
       PlacementTarget="{Binding ElementName=PART_Button}"
       IsOpen="False"
       Placement="Left" 
       StaysOpen="False"
       AllowsTransparency="True" 
       PopupAnimation="Fade"
       Focusable="True">
    <StackPanel>
       <Border Background="LightYellow">
             <TextBlock>Show Custom Rext</TextBlock>
       </Border>
    </StackPanel>
</Popup>

what is giving the error?


Triggers of an element only support EventTrigger so you can't use property triggers (Trigger). Look FrameworkElement.Triggers Property.

<Grid.Triggers>
    <EventTrigger RoutedEvent="UIElement.MouseEnter">
        <BeginStoryboard>
            <Storyboard>
                <BooleanAnimationUsingKeyFrames 
                    Storyboard.TargetName="Popup_PrevButton" 
                    Storyboard.TargetProperty="IsOpen">

                    <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Grid.Triggers>
0

精彩评论

暂无评论...
验证码 换一张
取 消