WPF Treeview Databinding Hierarchal Data with mixed types

Since you want the elements in the TreeView to have a list of children that consists of both Categories Products, you will want your Category ViewModel to have a collection that consists of both Categories and Products. For example, you could use a CompositeCollection to combine your existing collections: public class Category { public string …

Read more

WPF MVVM TreeView SelectedItem

You should not really need to deal with the SelectedItem property directly, bind IsSelected to a property on your viewmodel and keep track of the selected item there. A sketch: <TreeView ItemsSource=”{Binding TreeData}”> <TreeView.ItemContainerStyle> <Style TargetType=”{x:Type TreeViewItem}”> <Setter Property=”IsSelected” Value=”{Binding IsSelected}” /> </Style> </TreeView.ItemContainerStyle> </TreeView> public class TViewModel : INotifyPropertyChanged { private static object _selectedItem …

Read more

Vue JS : right click event directive

<button @contextmenu=”handler($event)”>r-click</button> methods : { handler: function(e) { //do stuff e.preventDefault(); } } @contextmenu will do the trick. The preventDefault is to avoid showing the default context menu. Shorter, as indincated in the comment : <button @contextmenu.prevent=”handler”>r-click</button> Now the prevent modifier takes care preventing default behaviour. Edit: For this to work with vue components, add …

Read more

AutoExpand treeview in WPF

You can set ItemContainerStyle and use IsExpanded property. <Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Grid> <TreeView> <TreeView.ItemContainerStyle> <Style TargetType=”{x:Type TreeViewItem}”> <Setter Property=”IsExpanded” Value=”True”/> </Style> </TreeView.ItemContainerStyle> <TreeViewItem Header=”Header 1″> <TreeViewItem Header=”Sub Item 1″/> </TreeViewItem> <TreeViewItem Header=”Header 2″> <TreeViewItem Header=”Sub Item 2″/> </TreeViewItem> </TreeView> </Grid> </Page> If you need to do this from code, you can write viewmodel for your …

Read more

AutoExpand treeview in WPF

You can set ItemContainerStyle and use IsExpanded property. <Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Grid> <TreeView> <TreeView.ItemContainerStyle> <Style TargetType=”{x:Type TreeViewItem}”> <Setter Property=”IsExpanded” Value=”True”/> </Style> </TreeView.ItemContainerStyle> <TreeViewItem Header=”Header 1″> <TreeViewItem Header=”Sub Item 1″/> </TreeViewItem> <TreeViewItem Header=”Header 2″> <TreeViewItem Header=”Sub Item 2″/> </TreeViewItem> </TreeView> </Grid> </Page> If you need to do this from code, you can write viewmodel for your …

Read more