TreeView- MVVM:fire command on selectedItemChanged
来源:互联网 发布:怎样在淘宝上做代销 编辑:程序博客网 时间:2024/04/28 21:24
Hi experts,
I am new to silverlight.
I have a small project based on MVVM. I am using tree view. I want to know how can I fire a command, which is defined in command.cs file, on selectedItemChange of tree view control.
my XAML file is as below
---------------------------------------------------XAML---------------------
<sdk:TreeView Height="230" HorizontalAlignment="Left" Name="trvWOList" VerticalAlignment="Top" Width="315" Margin="5"
ItemsSource="{Binding Path=lstWODetails, Mode=TwoWay}">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=lstItemCodesTree, Mode=TwoWay}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding strWOParent}">
</TextBlock>
<TextBlock Text="{Binding strItemCode}"></TextBlock>
<TextBlock Text="{Binding strstage}"></TextBlock>
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
-----------------------END------------------------
this is the command declaration I have in my viewmodel file
-----------------------------------ViewModel--------------
public ICommand test { get { return new check(); } }
----------------------END------------
below is my command definition
-------------------Command.cs----------------
public class check : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
MessageBox.Show("hi");
}
}
----------END-----------------
I am new to silverlight.
I have a small project based on MVVM. I am using tree view. I want to know how can I fire a command, which is defined in command.cs file, on selectedItemChange of tree view control.
my XAML file is as below
---------------------------------------------------XAML---------------------
<sdk:TreeView Height="230" HorizontalAlignment="Left" Name="trvWOList" VerticalAlignment="Top" Width="315" Margin="5"
ItemsSource="{Binding Path=lstWODetails, Mode=TwoWay}">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=lstItemCodesTree, Mode=TwoWay}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding strWOParent}">
</TextBlock>
<TextBlock Text="{Binding strItemCode}"></TextBlock>
<TextBlock Text="{Binding strstage}"></TextBlock>
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
-----------------------END------------------------
this is the command declaration I have in my viewmodel file
-----------------------------------ViewModel--------------
public ICommand test { get { return new check(); } }
----------------------END------------
below is my command definition
-------------------Command.cs----------------
public class check : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
MessageBox.Show("hi");
}
}
----------END-----------------
hello experts,
I resolved this issue.
I made a small change in XAML and it works. Hope it may help others.
<sdk:TreeView Height="230" HorizontalAlignment="Left" Name="trvWOList" VerticalAlignment="Top" Width="315" Margin="5"
ItemsSource="{Binding Path=lstWODetails, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction x:Name="abc" Command="{Binding Path=test, Mode=TwoWay}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=lstItemCodesTree, Mode=TwoWay}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding strWOParent}">
</TextBlock>
<TextBlock Text="{Binding strItemCode}"></TextBlock>
<TextBlock Text="{Binding strstage}"></TextBlock>
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
I resolved this issue.
I made a small change in XAML and it works. Hope it may help others.
<sdk:TreeView Height="230" HorizontalAlignment="Left" Name="trvWOList" VerticalAlignment="Top" Width="315" Margin="5"
ItemsSource="{Binding Path=lstWODetails, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction x:Name="abc" Command="{Binding Path=test, Mode=TwoWay}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=lstItemCodesTree, Mode=TwoWay}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding strWOParent}">
</TextBlock>
<TextBlock Text="{Binding strItemCode}"></TextBlock>
<TextBlock Text="{Binding strstage}"></TextBlock>
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
原文地址:http://forums.codeguru.com/archive/index.php/t-507076.html
- TreeView- MVVM:fire command on selectedItemChanged
- WPF自定义treeview绑定事件SelectedItemChanged
- MVVM实现TreeView
- MVVM --- Command 绑定
- WPF MVVM Command
- WPF TreeView Command
- MVVM on Android
- mvvm command的使用案例
- 短语:fire on all cylinders
- Create treeview on GLADE
- WPF:MVVM中Treeview/DragDrop用法
- 采用MVVM方式实现WPF的TreeView
- MVVM模式---Command与CommandParameter的使用
- Working on Command Line
- Common Command on linux
- syncsort command on unix
- Java command on linux
- git command on linux
- java心得--color、font、button、label、textfiel、textarea使用
- R语言书籍的学习路线图
- java心得--check、list、scroll、dialog
- H.264/AVC是同一个东西
- java心得--Swing
- TreeView- MVVM:fire command on selectedItemChanged
- Oracle数据库中修改列和拷贝表
- vi/vim搭建超级c/c++编程环境
- Android学习:Could not find XXX.apk!异常解决
- 黑马程序员 做完一个小东西的一些想法
- Java 中File 文件类
- 一个非常不错的数据库连接
- 第十三周任务三
- oracle dual表