Andree1

Hello,
I have a quetion.
have ListView with GridViewColumns and I need to make filters in each header(column), I want to have there TextBox where you can enter the text and Column will be filtred according this text.
I tried to do that via templates but there is a problem because Name o TextBox is needed in C# code for filtering, I don't know how to make template "dinamic"(only one template for every columnheader). If anyone know how to do that, pleas help.
Thank you Ondrej


Re: Windows Presentation Foundation (WPF) ListViewColumnHeader

lee d

when will the filtering actually happen, you can attached an event handler on the listbox that listens to textbox event. bit more details would help




Re: Windows Presentation Foundation (WPF) ListViewColumnHeader

Andree1

There is only one thing, i would like to know if it's possible to make template with TextBox and TextBlock. This template is for ColumnHeader, and then dinamicly change one attribute of TextBox(Name) which is in template. I think it should be possible by ussing binding but I don't know how. If anyone know pleas help ONdrej




Re: Windows Presentation Foundation (WPF) ListViewColumnHeader

Yi-Lun Luo - MSFT

Hello, do you want to filter the data based on what the user types in the TextBox If so, I guess what you want is the TextBox’s Text property. Since the TextBox is in a template, we can’t get it directly in the code. But here’s a walk around:

Create a TextBlock outside the template, set its Visibility property to Collapsed, so the user won’t see it. Give it a name such as text1. Now we can bind the TextBox’s Text in the template to the TextBlock’s Text:

Text="{Binding ElementName=text1, Path=Text}"

Since this binding is two way by default, whenever the TextBox’s Text updates, the TextBlock’s Text will also be updated. And we can access the TextBlock in our code since it’s not in a template. So we’ll get the text the user typed.






Re: Windows Presentation Foundation (WPF) ListViewColumnHeader

Andree1

Thank you ,
I have tried that but it doesn't work I can't get Text from TextBox to TextBlock's text.
Thanks ondrej




Re: Windows Presentation Foundation (WPF) ListViewColumnHeader

lee d

I am not sure about 'access name property'. if you want the name of the textbox, just bind the name of the Textbox to the textbox's Tag property