How to get the DataGridTextColumn sender's datagrid parent

Heisenberg

Hi I have a datagrid and the DataGridTextColumn shown in code below:

<DataGridTextColumn Header="" Width="1*" Binding="{Binding FORECAST_MIN, UpdateSourceTrigger=PropertyChanged,NotifyOnTargetUpdated=True}" >
 <DataGridTextColumn.EditingElementStyle>
    <Style TargetType="{x:Type TextBox}">
        <EventSetter Event="LostFocus" Handler="fMin_LostFocus" />                  
    </Style>
</DataGridTextColumn.EditingElementStyle>

Now in the LostFocus event, I'd like to get the parent datagrid from the sender. Code

private void fMin_LostFocus(object sender, RoutedEventArgs e)
{            
//Get the datagrid parent
}

Is there a easy way to do so? Thank you. Something like adding a Tag?

#

Both Jeff and OptimusPrime's answers work. It only allows me to choose one answer.

OptimusPrime

Jeff's answer should work. Since you mentioned "Tag". This might be another way to go? Probably not the most elegant way though.

<DataGridTemplateColumn Header="">
<DataGridTemplateColumn.CellTemplate>
        <DataTemplate>    
            <TextBox Text="{Binding FORECAST_MIN, UpdateSourceTrigger=PropertyChanged,NotifyOnTargetUpdated=True}" Tag="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}" LostFocus="fMin_LostFocus"/>    
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

and in your code:

private void fMin_LostFocus(object sender, RoutedEventArgs e)
    {
        var tb = (TextBox)sender;
        DataGrid parentDataGrid = (DataGrid)tb.Tag;
    }

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I get the sender's id using URL scheme in Swift

分類Dev

How can I get sender tag on OnBegin function?

分類Dev

How to get key of parent

分類Dev

JavaScript: get the sender element

分類Dev

How to know the sender in KVO?

分類Dev

How to get parent node in angular

分類Dev

When sending email with Postfix, how can I hide the sender’s IP and username in the Received header?

分類Dev

How to addTarget to UIButton without sender

分類Dev

UWP Datagrid Get Row

分類Dev

How to get the value of an element by traversing to parent div

分類Dev

How can i get rid of $parent in angular

分類Dev

How to get data from parent class (not extend)

分類Dev

How to implictly call parent class's constructor

分類Dev

How to access a directive's object in parent controller?

分類Dev

How to call parent's method in multilevel inheritance

分類Dev

WPF DataGrid cell binded on a parent property

分類Dev

How do I tweak "sender" in an event?

分類Dev

How to detect if Chromecast is already connected on Android Sender?

分類Dev

How to delete Line in the datagrid?

分類Dev

How to get the ID value of a parent element by class that is not immediate? jQuery

分類Dev

How to get the parent div id from the anchor child

分類Dev

How can I get the textContent that appears before the parent tag?

分類Dev

How to get the ref from a Mobiscroll child component into the parent

分類Dev

With apollo-server how to get child field info argument in parent

分類Dev

How to always get the same instance of parent class in php

分類Dev

How to get Parent class variable value in child class construct method

分類Dev

How to get the ID of parent Node on checkbox checked in jquery?

分類Dev

how to get mdi parent control from mdi child form

分類Dev

how to get parent and child text for the kendo menu in the select event

Related 関連記事

  1. 1

    How can I get the sender's id using URL scheme in Swift

  2. 2

    How can I get sender tag on OnBegin function?

  3. 3

    How to get key of parent

  4. 4

    JavaScript: get the sender element

  5. 5

    How to know the sender in KVO?

  6. 6

    How to get parent node in angular

  7. 7

    When sending email with Postfix, how can I hide the sender’s IP and username in the Received header?

  8. 8

    How to addTarget to UIButton without sender

  9. 9

    UWP Datagrid Get Row

  10. 10

    How to get the value of an element by traversing to parent div

  11. 11

    How can i get rid of $parent in angular

  12. 12

    How to get data from parent class (not extend)

  13. 13

    How to implictly call parent class's constructor

  14. 14

    How to access a directive's object in parent controller?

  15. 15

    How to call parent's method in multilevel inheritance

  16. 16

    WPF DataGrid cell binded on a parent property

  17. 17

    How do I tweak "sender" in an event?

  18. 18

    How to detect if Chromecast is already connected on Android Sender?

  19. 19

    How to delete Line in the datagrid?

  20. 20

    How to get the ID value of a parent element by class that is not immediate? jQuery

  21. 21

    How to get the parent div id from the anchor child

  22. 22

    How can I get the textContent that appears before the parent tag?

  23. 23

    How to get the ref from a Mobiscroll child component into the parent

  24. 24

    With apollo-server how to get child field info argument in parent

  25. 25

    How to always get the same instance of parent class in php

  26. 26

    How to get Parent class variable value in child class construct method

  27. 27

    How to get the ID of parent Node on checkbox checked in jquery?

  28. 28

    how to get mdi parent control from mdi child form

  29. 29

    how to get parent and child text for the kendo menu in the select event

ホットタグ

アーカイブ