Dav*_*her 5 silverlight datagrid updatesourcetrigger
我有一个Silverlight 2应用程序验证数据OnTabSelectionChanged.我立即开始希望UpdateSourceTrigger不仅允许LostFocus,因为如果单击选项卡而不选择控件,则在验证之前不会更新LINQ对象.
我通过将焦点设置为另一个控件然后返回OnTextChanged解决了TextBoxes的问题:
Private Sub OnTextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs)
txtSetFocus.Focus()
sender.Focus()
End Sub
Run Code Online (Sandbox Code Playgroud)
现在我试图在DataGrid中完成同样的黑客攻击.我的DataGrid使用在运行时为CellTemplate和CellEditingTemplate生成的DataTemplates.我尝试将TextChanged ="OnTextChanged"写入DataTemplate中的TextBox,但不会触发它.
有人有主意吗?
// xmlns:int is System.Windows.Interactivity from System.Windows.Interactivity.DLL)
// xmlns:behavior is your namespace for the class below
<TextBox Text="{Binding Description,Mode=TwoWay,UpdateSourceTrigger=Explicit}">
<int:Interaction.Behaviors>
<behavior:TextBoxUpdatesTextBindingOnPropertyChanged />
</int:Interaction.Behaviors>
</TextBox>
public class TextBoxUpdatesTextBindingOnPropertyChanged : Behavior<TextBox>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.TextChanged -= TextBox_TextChanged;
}
void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var bindingExpression = AssociatedObject.GetBindingExpression(TextBox.TextProperty);
bindingExpression.UpdateSource();
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6716 次 |
最近记录: |