I have a TreeView with HierarchicalDataTemplate. In the leaf node of the treeview, I have a button
binding to a command object, which have done the job as I expected.
Here is the working Xaml code:
<UserControl x:Class="YhControls.Views.ListFilesView"
</UserControl>
Now I want change the implementation from "Binding Commands" to "InvokeCommandAction".
Here is the version of "InvokeCommandAction":
<UserControl x:Class="YhControls.Views.ListFilesView"
</UserControl>
But, in "InvokeCommandAction" version, I got exception:
"Baml stream has unexpected record. Try to add to InvokeCommandAction,
but it is not a collection or which has TypeConverter."
Hope some one can help me.
binding to a command object, which have done the job as I expected.
Here is the working Xaml code:
<UserControl x:Class="YhControls.Views.ListFilesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:m="clr-namespace:YhCommon;assembly=YhCommon"
xmlns:vm="clr-namespace:YhControls.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Name="root">
<Grid.Resources>
<HierarchicalDataTemplate DataType = "{x:Type vm:Node}" ItemsSource = "{Binding Path=nodes}">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType = "{x:Type vm:Leaf}" ItemsSource = "{Binding Path=nodes}" >
<Button Content="{Binding Path=Name}" Command="{Binding ElementName=root,Path=DataContext.ShowFileCommand}" CommandParameter="{Binding }" />
</HierarchicalDataTemplate>
</Grid.Resources>
.....</UserControl>
Now I want change the implementation from "Binding Commands" to "InvokeCommandAction".
Here is the version of "InvokeCommandAction":
<UserControl x:Class="YhControls.Views.ListFilesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:m="clr-namespace:YhCommon;assembly=YhCommon"
xmlns:vm="clr-namespace:YhControls.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Name="root">
<Grid.Resources>
<HierarchicalDataTemplate DataType = "{x:Type vm:Node}" ItemsSource = "{Binding Path=nodes}">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType = "{x:Type vm:Leaf}" ItemsSource = "{Binding Path=nodes}" >
<Button Content="{Binding Path=Name}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" >
<i:InvokeCommandAction Command="{Binding ElementName=root,Path= DataContext.ShowFileCommand}" CommandParameter="{Binding }" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</HierarchicalDataTemplate>
</Grid.Resources>
...</UserControl>
But, in "InvokeCommandAction" version, I got exception:
"Baml stream has unexpected record. Try to add to InvokeCommandAction,
but it is not a collection or which has TypeConverter."
Hope some one can help me.