Click here to Skip to main content
15,891,009 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I am new in WPF.
As you see in this picture:
http://api.ning.com/files/3FX8CRo2Q3IZ...
I have a textbox that filters items of listbox.
This is my WPF code:
XML
<Grid>
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="28,31,0,0" Name="textBlock1" Text="Filter Tags:" VerticalAlignment="Top" />
    <TextBox Text="{Binding Path=FilterText,Mode=TwoWay}"  Height="23" HorizontalAlignment="Left" Margin="91,28,0,0" Name="textBoxFilterTags" VerticalAlignment="Top" Width="120" TextChanged="textBoxFilterTags_TextChanged" />
    <ListBox ItemsSource="{Binding Path=Filter}"  Height="178" HorizontalAlignment="Left" Margin="12,71,0,0" Name="listBoxTags" VerticalAlignment="Top" Width="254">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding Path=Tick,Mode=TwoWay}" Margin="3,1,1,1" />
                    <TextBlock Text="{Binding Path=Name}" Margin="3,1,1,1" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>


my listbox is binded to a property called:
C#
public ObservableCollection<tagtick> Filter
{
    get
    {
       .... // filtering based on filter text
    }
}


Now, my problem is that when I type in the filter text, the listbox should update the filter. I tried using UpdateSourceTrigger but it didnt work. can some one tell me how to trigger the binding update when the text of textbox change?

Thanks in advance.
Posted
Updated 26-Aug-11 16:34pm
v2

1 solution

It's advisable to control this binding through code, one reason being that the DataTemplate of your ListBox have changed to a parent element of StackPanel(with two other element inside) and the TextBlock inside the StackPanel may not be directly accessible especially for a TwoWay Binding without doing some casting in code. I suggest that you do your filtering through code and not XAML.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900