2010-07-30 76 views
0

我有一個圖像和一個彈出菜單。當點擊圖像彈出窗口時應該打開。請幫我一個彈出式菜單

我開始這樣,現在我卡住了。

 <Image x:Name="LockImage" Source="/Lock.png"> 
      <Image.Triggers> 
       <EventTrigger RoutedEvent="MouseDown"> 
        // ?????? WHAT's here? 
       </EventTrigger> 
      </Image.Triggers> 
     </Image> 
     <Popup x:Name="LockPopup" PlacementTarget="{Binding ElementName=LockImage}"> 
      <TextBlock Text="This is a popup" /> 
     </Popup> 

UPD ......哎呀,其實我忘了......我想可以不立即,而是經過一兩秒鐘所示的彈出窗口。如果只是一個點擊,它會是別的...(默認操作)

回答

2

這是你想要做的解決方案。延遲時間可以在Storyboard定義中設置。將此代碼插入到新的wpf應用程序項目Window.xaml文件中。

<Window.Resources> 
     <Storyboard x:Key="ShowPopup"> 
      <BooleanAnimationUsingKeyFrames Storyboard.TargetName="LockPopup" Storyboard.TargetProperty="(Popup.IsOpen)"> 
       <DiscreteBooleanKeyFrame KeyTime="00:00:00.5" Value="True" /> 
      </BooleanAnimationUsingKeyFrames> 
     </Storyboard> 

     <Storyboard x:Key="HidePopup" Storyboard.TargetName="LockPopup" Storyboard.TargetProperty="(Popup.IsOpen)"> 
      <BooleanAnimationUsingKeyFrames> 
       <DiscreteBooleanKeyFrame KeyTime="00:00:00.5" Value="False" /> 
      </BooleanAnimationUsingKeyFrames> 
     </Storyboard> 
    </Window.Resources> 
    <Grid x:Name="grid" ShowGridLines="True"> 
     <Image x:Name="LockImage" Stretch="None" > 
      <Image.Source> 
       <DrawingImage> 
        <DrawingImage.Drawing> 
         <GeometryDrawing Brush="Black"> 
          <GeometryDrawing.Geometry> 
           <EllipseGeometry RadiusX="10" RadiusY="10"/> 
          </GeometryDrawing.Geometry> 
         </GeometryDrawing> 
        </DrawingImage.Drawing> 
       </DrawingImage> 
      </Image.Source> 
      <Image.Triggers> 
       <EventTrigger RoutedEvent="Image.MouseLeftButtonDown"> 
        <BeginStoryboard Storyboard="{StaticResource ShowPopup}"/> 
       </EventTrigger> 
       <EventTrigger RoutedEvent="Image.MouseLeave"> 
        <BeginStoryboard Storyboard="{StaticResource HidePopup}"/> 
       </EventTrigger> 
      </Image.Triggers> 
     </Image> 
     <Popup x:Name="LockPopup" PlacementTarget="{Binding ElementName=LockImage}" DataContext="{Binding}" Placement="Bottom"> 
      <TextBlock Text="This is a popup" Background="White" Foreground="Black" /> 
     </Popup>  
    </Grid> 
+0

噢謝謝...它可以用於任何點擊。現在...如果我想在幾秒鐘後顯示彈出窗口,但如果用戶沒有等待,只需按下按鈕,它將啓動默認事件。例如顯示一條消息? – Agzam 2010-07-30 15:27:48

+0

是的,它會觸發定義的事件,然後還會觸發故事板。 – 2010-07-30 15:38:38