首页 新闻 搜索 专区 学院

wpf 绑定问题

0
悬赏园豆:20 [待解决问题]
  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 }
View Code

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>
View Code

<MenuItem Header="批注" Command="{Binding MarkCommand}"></MenuItem>
<MenuItem Header="打开" Command="{Binding OpenFileCommand}"></MenuItem>

如何能得到workspace中的两个command?

summeney的主页 summeney | 初学一级 | 园豆:141
提问于:2013-11-28 14:38
< >
分享
所有回答(2)
0

看你的意思是MenuItem点击事件,事件中处理Command,这样的话再XAML的MenuItem添加click事件,在CS的click事件执行Command或你说的Command绑定

iEvent | 园豆:529 (小虾三级) | 2013-11-28 15:18
0

有问题啊?不是就是这样的吗?

幕三少 | 园豆:1384 (小虾三级) | 2013-11-29 16:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册