wpf: How popup a usercontrol?

前端 未结 2 1784
日久生厌
日久生厌 2020-12-31 20:06

Background: I have a project which use the datagrid to display the data, and the datagrid has a rowdetail column which include a usercontrol. The usercontrol has some TextBo

2条回答
  •  囚心锁ツ
    2020-12-31 20:17

    You can use the Popup control. Attach a Popup to the current row of your datagrid, probably when you click the button is a good place to create the popup and place it as a child of one of cells in the row you are in.
    Then you can add the usercontrol to the popup and then 'show' the popup. This way, the DataContext for the popup and thus for the usercontrol is inherited from the containing row in the datagrid.

    Below is a very simple implementation of a Popup control just using XAML:

    
      
      
        
          
        
      
    
    

    The popup is included in the stackpanel, but is only visible, IsOpen, when the checkbox is checked. You would place your usercontrol in the popup, where I have put the border and textblock. Since the popup is a member of the stackpanel, it automatically uses the DataContext of the stackpanel if it does not have one of its own.

    In your instance the stackpanel I am showing would be analogous to your DataGrid row.

提交回复
热议问题