internal partial class Workspace:Base.ViewModelBase { #region property private Modles.FileFolderTree _current; //当前树节点(文件夹) public Modles.FileFolderTree Current { set { if (value.Self.FC == Modles.FileClass.Folder) { _current = value; this.RaisePropertyChanged("Current"); this.InfCurrent = value.Self.FileFolder_Inf; //显示详细信息 } } get { return _current; } }#endregion #region Command
public Base.DelegateCommand MarkCommand { set; get; } public Base.DelegateCommand OpenFileCommand { set; get; } #endregion #region Method /// <summary> /// 文件批注 /// </summary> public void mark(object obj) { try { this.MarkFile = this.CurrentFile.Self; } catch (Exception ex) { } } /// <summary> /// 打开文件 /// </summary> public void openfile(object obj) { try { this.OpenFile = this.CurrentFile.Self; } catch (Exception ex) { } Process pro = new Process(); pro = Process.Start(@"E:\软件\photoshopcs5\Photoshop.exe",this.OpenFile.Path); } #endregion }
Window的DataContext是Workspace
ListBox的 ItemsSource="{Binding Current.Children}"
问题:
<Style x:Key="filelistshow_listbox_style" TargetType="ListBox"> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ListBoxItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="批注" Command="{Binding MarkCommand}"></MenuItem> <MenuItem Header="打开" Command="{Binding OpenFileCommand}"></MenuItem> </ContextMenu> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <Grid Width="100" Height="50" Margin="0 0 10 0"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Image Source="{Binding Self.ICO}"></Image> <TextBlock Foreground="#ffffff" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Self.Text}" Grid.Row="1"></TextBlock> <TextBlock></TextBlock> </Grid> </DataTemplate> </Setter.Value> </Setter> </Style>
<MenuItem Header="批注" Command="{Binding MarkCommand}"></MenuItem>
<MenuItem Header="打开" Command="{Binding OpenFileCommand}"></MenuItem>
如何能得到workspace中的两个command?
看你的意思是MenuItem点击事件,事件中处理Command,这样的话再XAML的MenuItem添加click事件,在CS的click事件执行Command或你说的Command绑定
有问题啊?不是就是这样的吗?