开发者

WPF TextBox lostfocus as attached property

开发者 https://www.devze.com 2023-01-04 06:34 出处:网络
I have a Grid with many TextBoxes and I want to call Notif开发者_开发问答yPropertyChanged()methodto update some other controls everytime one of these TextBox-es changed the value = lost the focus (I d

I have a Grid with many TextBoxes and I want to call Notif开发者_开发问答yPropertyChanged() method to update some other controls everytime one of these TextBox-es changed the value = lost the focus (I don't want to use PropertyChanged as UpdateSourceTrigger)

This is what I can do:

<Grid TextBoxBase.TextChanged="My_TextChanged"  >
...
</Grid>

I need something like:

TextBoxBase.OnLostFocus


Use the lost focus event

TextBox.LostFocus="OnTextBoxLostFocus"

Filter on textboxes ;)

private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)
{
    if(!(e.OriginalSource is TextBox))
        return;

    //Do stuff
}

If your properties are not changed, your Textboxes will not be updated however. You should consider mutating the data those other TextBoxes are bound to, instead of using LostFocus to update your model.

Good luck!


TextBoxBase.LostFocus is, I suspect, the event you're looking for.

It's listed here: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase_events.aspx - but it's defined on UIElement - so you possibly want to try UIElement.LostFocus if the above doesn't work in markup.

0

精彩评论

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