How to open a WPF Popup when another control is clicked, using XAML markup only?

后端 未结 5 2113
梦如初夏
梦如初夏 2020-11-28 21:34

I\'ve got two controls, a TextBlock and a PopUp. When the user clicks (MouseDown) on the textblock, I want to display the popup. I would think that I could do this with an E

5条回答
  •  攒了一身酷
    2020-11-28 22:29

    I did something simple, but it works.

    I used a typical ToggleButton, which I restyled as a textblock by changing its control template. Then I just bound the IsChecked property on the ToggleButton to the IsOpen property on the popup. Popup has some properties like StaysOpen that let you modify the closing behavior.

    The following works in XamlPad.

     
       
        
          
            Click Me Here!!
                
        
      
      
        
          I'm the popup
        
       
     
    

提交回复
热议问题