简体   繁体   English

用于PropertyChanged和LostFocus的TextBox UpdateSourceTrigger

[英]TextBox UpdateSourceTrigger for PropertyChanged and LostFocus

Hello I have question about a wpf/xaml text box c# implementation. 您好,我对WPF / XAML文本框C#实现有疑问。

I am trying to figure out how in my c# code to know what the UpdateSourceTrigger is being used. 我试图弄清楚如何在我的C#代码中知道正在使用什么UpdateSourceTrigger。 I am a newbie, so I would very much appreciate if people are patient with me and helpful. 我是新手,所以如果人们对我耐心并且乐于助人,我将不胜感激。

In my C# I need to know how the data in the Text box is trying to be accessed using UpdateSourceTrigger. 在我的C#中,我需要知道如何尝试使用UpdateSourceTrigger访问“文本”框中的数据。 I know the property changed when my OnPropertyChanged() is called. 我知道调用OnPropertyChanged()时属性已更改。 But I also need to know how if the user is trying to use LostFocus or PropertyChanged in the C# code. 但是我还需要知道用户是如何尝试在C#代码中使用LostFocus或PropertyChanged。 This is so I can do some special processing for either case. 这样,无论哪种情况我都可以做一些特殊处理。

xaml a

<TextBox>
    <TextBox.Text>
        <Binding Source="{StaticResource myDataSource}" Path="Name"
        UpdateSourceTrigger="PropertyChanged"/>
    </TextBox.Text>
</TextBox>    

c# C#

protected void OnPropertyChanged(string name)
{
    // If UpdateSourceTrigger= PropetyChanged then process one way
    // If UpdateSourceTrigger= LostFocus then process one way
}

Is there any other methods that get called when using LostFocus? 使用LostFocus时还有其他方法可以调用吗?

Thanks you 谢谢

You will have to get a reference to your TextBlock and get the binding expression then you will have access to the Binding information 您将必须获取对TextBlock的引用并获取绑定表达式,然后才能访问Binding信息。

Example:(no error/null checking) 示例:(无错误/空检查)

<TextBox x:Name="myTextblock">
     <TextBox.Text>
        <Binding Source="{StaticResource myDataSource}" Path="Name"
        UpdateSourceTrigger="PropertyChanged"/>
     </TextBox.Text>
</TextBox>


var textblock = this.FindName("myTextBlock") as TextBlock;
var trigger = textblock.GetBindingExpression(TextBlock.TextProperty).ParentBinding.UpdateSourceTrigger;
// returns "PropertyChanged"

another way of getting the binding object is: 获取绑定对象的另一种方法是:

Binding binding = BindingOperations.GetBinding(myTextBox, TextBox.TextProperty);

if (binding.UpdateSourceTrigger.ToString().Equals("LostFocus"))
{

}
else
{

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mode = TwoWay,UpdateSourceTrigger = PropertyChanged还是LostFocus? - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged or LostFocus? WPF TextBox UpdateSourceTrigger = LostFocus不断更新数据 - WPF TextBox UpdateSourceTrigger=LostFocus keeps updating data Windows Phone 7文本框的“ UpdateSourceTrigger = PropertyChanged”等效项 - “UpdateSourceTrigger=PropertyChanged” equivalent for a Windows Phone 7 TextBox UpdateSourceTrigger = PropertyChanged和Converter - UpdateSourceTrigger=PropertyChanged and Converter 在TextBox上的UpdateSourceTrigger.PropertyChanged和INotifyChanged DataBinding Silverlight 5在TextBox中键入非常慢 - UpdateSourceTrigger.PropertyChanged and INotifyChanged on TextBox DataBinding Silverlight 5 typing in TextBox is extremely slow 用户无法输入&#39;。&#39; 在文本框中已绑定到浮点值,而UpdateSourceTrigger是WPF中的PropertyChanged - User can't type '.' in the textbox that have been bound to a float value while UpdateSourceTrigger is PropertyChanged in WPF WPF绑定未使用UpdateSourceTrigger = PropertyChanged更新 - WPF Binding not updating with UpdateSourceTrigger=PropertyChanged 无法通过UpdateSourceTrigger = PropertyChanged更新WPF - Trouble updating WPF with UpdateSourceTrigger = PropertyChanged 控件失去对UpdateSourceTrigger = PropertyChanged的关注 - Control looses focus on UpdateSourceTrigger = PropertyChanged Prism + MVVM +访问键+ UpdateSourceTrigger =“ LostFocus”-这无法让我保存更新的文本框而不会先失去焦点 - Prism + MVVM + Access Keys + UpdateSourceTrigger=“LostFocus” — This doesn't let me save an updated textbox without first losing focus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM