开发者

WPF Popup control on ImageMouseLeftButtonDown disappears immediately

开发者 https://www.devze.com 2023-02-26 04:25 出处:网络
I have a popup defined as follows, <Popup x:Name=\"popLines\" Placement=\"Bottom\" IsOpen=\"False\" Width=\"145\" Height=\"42\"

I have a popup defined as follows,

<Popup x:Name="popLines"
         Placement="Bottom"
           IsOpen="False"
           Width="145" Height="42"
           StaysOpen="False"
           PopupAnimation=开发者_Go百科"Fade"
           AllowsTransparency="True"
           HorizontalOffset="-2" VerticalOffset="0">
                    <Grid Margin="2">
                        <Path StrokeThickness="0.7" StrokeLineJoin="Round" Fill="#FFFFFFFF" Stretch="Fill" Stroke="Black"  Data="M6.5,0.5 L30.167,0.5 30.167,8.4999992 190.16701,8.4999992 190.16701,44.166001 0.5,44.166001 0.5,8.4999992 6.5,8.4999992 6.5,0.5 z">
                        </Path>
                        <Grid>
                        <StackPanel Orientation="Horizontal">
                            <TextBox BorderBrush="Black" BorderThickness="0.5" Margin="5,10,2,2" Width="110" Height="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ToolTip="Excel File Path"></TextBox>
                            <Image Source="/App_Desktop;component/Resources/save.png" Margin="2,10,5,2" Width="16" Height="16"></Image>
                        </StackPanel>
                        </Grid>
                    </Grid>
                </Popup>

I set IsOpen=true when an image MouseLeftButtonDown event fires.Except, the popup disappears as soon as it appears. What is going wrong?


I think what happens is, that the the MouseLeftButtonUp event fires while the Mouse is not over the Popup. Try holding the mousebutton down and move your mouse so it is above the popup to see if it stays open, and then release the mousebutton.

you can solve this by setting StaysOpen="True" or by setting IsOpen=true in a click eventhandler or MouseButtonUp eventhandler.

Also using your example with the image, you could have a transparent area right above the image in your popup visualtree that 'captures' the MouseUp event when the popup is open. you would have to change the placement option and bind that area to the image's width and height properties.

0

精彩评论

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