wpf中的文本框处理程序 [英] Textbox handler in wpf

查看:83
本文介绍了wpf中的文本框处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码....我正面临着文本框处理程序的问题...处理程序的问题是,当我尝试在文本框中输入任何值时,它是自动事件仅调用第一次按键。 ...那么是否有任何其他事件允许用户将数据输入文本框然后事件应该调用如On Blur????如果有人可以做,请帮助我提供代码....代码是动态完成所有动态没有使用xaml

This is my code.... i am facing problem with text box handler... problem with handler is that when i am try to enter any value in text box it is automatically event is calling for first key press only.... So is there any other event which allows user to enter data into text box an then the event should call like "On Blur"???? If anyone can do please help me bye providing code....Code is done everything dynamically no xaml is used

private void CreateDynamicGridView(DataSet dsBillingDetails)
       {

          // Create a GridView
           int rowPosition = 0;
           for (int index = 1; index < dsBillingDetails.Tables.Count; index++)
           {

                   DataGrid grdCharges = new DataGrid();
                   grdCharges.ItemsSource = dsBillingDetails.Tables[index].DefaultView;
                   grdCharges.AutoGenerateColumns = false;

                   Style grdHeaderStyle = this.FindResource("grdHeaderStyle") as Style;

                   <big>//Adding Button Dynamically</big>
                   DataGridTemplateColumn dgtcDel = new DataGridTemplateColumn();
                   FrameworkElementFactory fefDelButton = new FrameworkElementFactory(typeof(Button));
                   BitmapImage biDeleteIcon = new BitmapImage();

                   fefDelButton.SetBinding(Button.TagProperty, new Binding("LineItemID"));
                   fefDelButton.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(btnDelete_Click), true);
                   DataTemplate buttonTemplate = new DataTemplate();

                   dgtcDel.Header = "D";
                   dgtcDel.HeaderStyle = grdHeaderStyle;
                   buttonTemplate.VisualTree = fefDelButton;
                   dgtcDel.CellTemplate = buttonTemplate;
                   biDeleteIcon.BeginInit();
                   biDeleteIcon.UriSource = new Uri(@"..\Images\Deleteicon.png", UriKind.Relative);
                   biDeleteIcon.EndInit();

                   fefDelButton.SetValue(Image.SourceProperty, biDeleteIcon);
                   fefDelButton.SetValue(Image.VisibilityProperty, Visibility.Visible);
                   grdCharges.Columns.Add(dgtcDel);

                   //create a template column for text box
                   DataGridTemplateColumn dgtTextBox = new DataGridTemplateColumn();

                   //set title of column
                   dgtTextBox.Header = "Line Item Units";
                   dgtTextBox.Width = 150;

                   DataTemplate dtTextBox = new DataTemplate();
                   FrameworkElementFactory fefTextBox = new FrameworkElementFactory(typeof(System.Windows.Controls.TextBox));

              //<big>Adding Hanler THIS IS THE ISSUE</big>
                 fefTextBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(txtUnitCount_Changed));
                   dtTextBox.VisualTree = fefTextBox;
                   dgtTextBox.CellTemplate = dtTextBox;
                   grdCharges.Columns.Add(dgtTextBox);

                   grdBillingDetails.Children.Add(grdCharges);

                   //   grdCharges.Style = grdHeaderStyle;
                   Grid.SetRow(grdCharges, rowPosition + 1);
                   rowPosition = rowPosition + 2;
               }
       }

推荐答案

这样做是因为当您在文本框中输入文本时,TextChanged事件被触发。



我认为OnBlur将是一个可行的选择,因为它会在控件失去焦点时触发。







看看这些文章:



点击 [ ^ ]







LostFocus [ ^ ]



好​​像LostFocus就是你的活动。
It is doing that because when you enter text into the textbox, the TextChanged event is fired.

I think "OnBlur" would be a viable alternative since it fires when the control loses focus.



Have a look at these articles:

Click[^]

and

LostFocus[^]

It appears as though "LostFocus" is the event for you.


这篇关于wpf中的文本框处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆