Filter child's in a tree view using MVVM
up vote
0
down vote
favorite
Name1(tree node)
Car1(child)
Car2(child)
Car3(child)
Name2(tree node)
Car4(child)
Car5(child)
Car6(child)
It's possible to display only the children in a tree-view scenario using Test_Filter(object sender, FilterEventArgs e)?
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
In code:
private void Search_TextChanged(object sender, TextChangedEventArgs e) => this.RefreshDS();private void RefreshDS() => this.WhenIdle(
() =>
{
if (this.TryFindResource("treeSource") is CollectionViewSource cvs)
{
cvs?.View?.Refresh();
}
});
private void TreeViewCollectionViewSource_Filter(object sender, FilterEventArgs e)
{
if (string.IsNullOrWhiteSpace(this.Search.Text))
{
e.Accepted = true;
return;
}
if (!(e.Item is NameMVVMModel item))
{
e.Accepted = false;
}
else
{
var searchTerm = this.Search.Text;
//list that contains every car
var t = item.NameModel;
foreach (var item1 in t)
{
e.Accepted =
item1.Car?.CurrentCultureContainsInsensitive(searchTerm) ?? false;
}
}
}`
For the moment I can filter only "Names" but I want to filter Cars in my example( Names contains list of "Cars" It is possible to filter Cars using my approach?
filter
add a comment |
up vote
0
down vote
favorite
Name1(tree node)
Car1(child)
Car2(child)
Car3(child)
Name2(tree node)
Car4(child)
Car5(child)
Car6(child)
It's possible to display only the children in a tree-view scenario using Test_Filter(object sender, FilterEventArgs e)?
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
In code:
private void Search_TextChanged(object sender, TextChangedEventArgs e) => this.RefreshDS();private void RefreshDS() => this.WhenIdle(
() =>
{
if (this.TryFindResource("treeSource") is CollectionViewSource cvs)
{
cvs?.View?.Refresh();
}
});
private void TreeViewCollectionViewSource_Filter(object sender, FilterEventArgs e)
{
if (string.IsNullOrWhiteSpace(this.Search.Text))
{
e.Accepted = true;
return;
}
if (!(e.Item is NameMVVMModel item))
{
e.Accepted = false;
}
else
{
var searchTerm = this.Search.Text;
//list that contains every car
var t = item.NameModel;
foreach (var item1 in t)
{
e.Accepted =
item1.Car?.CurrentCultureContainsInsensitive(searchTerm) ?? false;
}
}
}`
For the moment I can filter only "Names" but I want to filter Cars in my example( Names contains list of "Cars" It is possible to filter Cars using my approach?
filter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Name1(tree node)
Car1(child)
Car2(child)
Car3(child)
Name2(tree node)
Car4(child)
Car5(child)
Car6(child)
It's possible to display only the children in a tree-view scenario using Test_Filter(object sender, FilterEventArgs e)?
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
In code:
private void Search_TextChanged(object sender, TextChangedEventArgs e) => this.RefreshDS();private void RefreshDS() => this.WhenIdle(
() =>
{
if (this.TryFindResource("treeSource") is CollectionViewSource cvs)
{
cvs?.View?.Refresh();
}
});
private void TreeViewCollectionViewSource_Filter(object sender, FilterEventArgs e)
{
if (string.IsNullOrWhiteSpace(this.Search.Text))
{
e.Accepted = true;
return;
}
if (!(e.Item is NameMVVMModel item))
{
e.Accepted = false;
}
else
{
var searchTerm = this.Search.Text;
//list that contains every car
var t = item.NameModel;
foreach (var item1 in t)
{
e.Accepted =
item1.Car?.CurrentCultureContainsInsensitive(searchTerm) ?? false;
}
}
}`
For the moment I can filter only "Names" but I want to filter Cars in my example( Names contains list of "Cars" It is possible to filter Cars using my approach?
filter
Name1(tree node)
Car1(child)
Car2(child)
Car3(child)
Name2(tree node)
Car4(child)
Car5(child)
Car6(child)
It's possible to display only the children in a tree-view scenario using Test_Filter(object sender, FilterEventArgs e)?
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
In code:
private void Search_TextChanged(object sender, TextChangedEventArgs e) => this.RefreshDS();private void RefreshDS() => this.WhenIdle(
() =>
{
if (this.TryFindResource("treeSource") is CollectionViewSource cvs)
{
cvs?.View?.Refresh();
}
});
private void TreeViewCollectionViewSource_Filter(object sender, FilterEventArgs e)
{
if (string.IsNullOrWhiteSpace(this.Search.Text))
{
e.Accepted = true;
return;
}
if (!(e.Item is NameMVVMModel item))
{
e.Accepted = false;
}
else
{
var searchTerm = this.Search.Text;
//list that contains every car
var t = item.NameModel;
foreach (var item1 in t)
{
e.Accepted =
item1.Car?.CurrentCultureContainsInsensitive(searchTerm) ?? false;
}
}
}`
For the moment I can filter only "Names" but I want to filter Cars in my example( Names contains list of "Cars" It is possible to filter Cars using my approach?
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<CollectionViewSource
x:Key="treeSource"
Filter="TreeViewCollectionViewSource_Filter"
IsLiveFilteringRequested="True"
Source="{Binding Path=NameModel}"
>
</CollectionViewSource>
***********
<TreeView
ItemsSource="{Binding Source={StaticResource treeSource}}"
SnapsToDevicePixels="True"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" KeyDown="nameTreeview_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding NameModel}">
<TextBlock
FontFamily="Segoe UI"
Foreground="Blue"
Text="{Binding SomeProperty}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CarModel}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
filter
filter
asked Nov 7 at 12:51
Little_quitty
93
93
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189818%2ffilter-childs-in-a-tree-view-using-mvvm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown