TextInput事件不响应。
KeyUp事件只响应第一次输入。
10 个解决方案
#1
#2
哈哈……
终于碰上一个用WPF的了。
我告诉你一个最方便的方法。
你可以重写combobox的controltemplate
你用xamlpad查一下就知道
在combobox的视觉树里面,会有textbox,你响应它的textchanged事件就好了。
终于碰上一个用WPF的了。
我告诉你一个最方便的方法。
你可以重写combobox的controltemplate
你用xamlpad查一下就知道
在combobox的视觉树里面,会有textbox,你响应它的textchanged事件就好了。
#3
up
#4
通过Combobox的视觉树找到TextBox就可以了哇,TextBox的Name是PART_EditableTextBox
#5
视觉树怎么用?具体的写法有没有……
#6
如果你装了VS的话,那么在microsoft sdks\windows\v6.0下面你可以找到这个xamlpad程序,
用这个来查看视觉树。
重写controltemplate可以看MSDN,很全。
combobox里面textbox 的name是PART_EditableTextBox
用这个来查看视觉树。
重写controltemplate可以看MSDN,很全。
combobox里面textbox 的name是PART_EditableTextBox
#7
可以试试OnPreviewTextInput事件,没有时间亲自试,帮顶
#8
我是要靠这样搞定的:(vb.net)
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#9
我是要靠这样搞定的:(vb.net)
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#10
我找到方法了:
第一种:如http://liuqi740924.blog.163.com/blog/static/803471542010834316688/
大哥所说
第二种:通过楼上的楼上的楼上的……所说的VisualTree,具体使用系统内置的VisualTreeHelper类
例如你想找this.cbStandards的TextBox控件,可如下索取
((TextBox)VisualTreeHelper.GetChild( (DependencyObject)(VisualTreeHelper.GetParent( (DependencyObject)this.cbStandards)),1))
你可以给这个东东加事件。
第一种:如http://liuqi740924.blog.163.com/blog/static/803471542010834316688/
大哥所说
第二种:通过楼上的楼上的楼上的……所说的VisualTree,具体使用系统内置的VisualTreeHelper类
例如你想找this.cbStandards的TextBox控件,可如下索取
((TextBox)VisualTreeHelper.GetChild( (DependencyObject)(VisualTreeHelper.GetParent( (DependencyObject)this.cbStandards)),1))
你可以给这个东东加事件。
#1
#2
哈哈……
终于碰上一个用WPF的了。
我告诉你一个最方便的方法。
你可以重写combobox的controltemplate
你用xamlpad查一下就知道
在combobox的视觉树里面,会有textbox,你响应它的textchanged事件就好了。
终于碰上一个用WPF的了。
我告诉你一个最方便的方法。
你可以重写combobox的controltemplate
你用xamlpad查一下就知道
在combobox的视觉树里面,会有textbox,你响应它的textchanged事件就好了。
#3
up
#4
通过Combobox的视觉树找到TextBox就可以了哇,TextBox的Name是PART_EditableTextBox
#5
视觉树怎么用?具体的写法有没有……
#6
如果你装了VS的话,那么在microsoft sdks\windows\v6.0下面你可以找到这个xamlpad程序,
用这个来查看视觉树。
重写controltemplate可以看MSDN,很全。
combobox里面textbox 的name是PART_EditableTextBox
用这个来查看视觉树。
重写controltemplate可以看MSDN,很全。
combobox里面textbox 的name是PART_EditableTextBox
#7
可以试试OnPreviewTextInput事件,没有时间亲自试,帮顶
#8
我是要靠这样搞定的:(vb.net)
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#9
我是要靠这样搞定的:(vb.net)
#Region "TextChanged"
Private Sub UserName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles UserName.KeyUp
UserNameTextChanged()
End Sub
Private Sub UserName_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles UserName.LostFocus
UserNameTextChanged()
End Sub
Private Sub UserName_PreviewTextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles UserName.PreviewTextInput
UserNameTextChanged()
End Sub
Private Sub UserNameTextChanged()
If UserName.Text Is Nothing Then
Else
If UserName.Text.Trim = String.Empty Then
ButtonRemove.Visibility = Windows.Visibility.Hidden
Else
For Each Item In UserName.Items
If Item = UserName.Text.Trim Then
ButtonRemove.Visibility = Windows.Visibility.Visible
Else
ButtonRemove.Visibility = Windows.Visibility.Hidden
End If
Next
End If
End If
End Sub
#End Region
#10
我找到方法了:
第一种:如http://liuqi740924.blog.163.com/blog/static/803471542010834316688/
大哥所说
第二种:通过楼上的楼上的楼上的……所说的VisualTree,具体使用系统内置的VisualTreeHelper类
例如你想找this.cbStandards的TextBox控件,可如下索取
((TextBox)VisualTreeHelper.GetChild( (DependencyObject)(VisualTreeHelper.GetParent( (DependencyObject)this.cbStandards)),1))
你可以给这个东东加事件。
第一种:如http://liuqi740924.blog.163.com/blog/static/803471542010834316688/
大哥所说
第二种:通过楼上的楼上的楼上的……所说的VisualTree,具体使用系统内置的VisualTreeHelper类
例如你想找this.cbStandards的TextBox控件,可如下索取
((TextBox)VisualTreeHelper.GetChild( (DependencyObject)(VisualTreeHelper.GetParent( (DependencyObject)this.cbStandards)),1))
你可以给这个东东加事件。