XAMLPARSEEXCEPTION [英] XAMLPARSEEXCEPTION

查看:77
本文介绍了XAMLPARSEEXCEPTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试这样做:

hey guys, i am trying to do this: 

<ListBox SelectionMode="Multiple" x:Name="DependenciesListBox" ItemsSource="{Binding Path=Projects}"  HorizontalAlignment="Left" Height="296" Margin="20,30,0,0" VerticalAlignment="Top" Width="274">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type local:Project}">
                    <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" Content="{Binding Path=Path.FullName}"  >
                        <i:Interaction.Triggers >
                            <i:EventTrigger EventName="Checked">
                                <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, 
                                   AncestorType={x:Type Window}}, Path=DataContext.Command}" CommandParameter="{Binding ElementName=DependenciesListBox, Path=SelectedItems}"></i:InvokeCommandAction>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

我得到这个异常说:

XamlParseException : trying to add to add to InvokeCommandAction which is not a collection or has TypeConverter.

有人可以帮助我吗?

推荐答案


穆罕默德(HAOUAT Mohamed),


Hi HAOUAT Mohamed,

我修改了您的代码,它可以正常工作,您可以参考以下示例.

I modified your code and it is working, you can refer to the following example.

XAML:

 <ListBox  SelectionMode="Single" x:Name="DependenciesListBox" ItemsSource="{Binding Projects}"  HorizontalAlignment="Left" Height="296" Margin="20,30,0,0" VerticalAlignment="Top" Width="274" SelectedItem="{Binding selectProject}">
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" Content="test1"  >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                                <i:InvokeCommandAction  Command="{Binding Path=DataContext.Command,RelativeSource={RelativeSource AncestorType={x:Type  ListBox}}}" CommandParameter="{Binding Path=DataContext.selectProject ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"  />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

XAML.CS:

public partial class ListBoxcheckevent : Window
    {
        viewmodelss vss = new viewmodelss();

        public ListBoxcheckevent()
        {
            InitializeComponent();
            DependenciesListBox.DataContext = vss;
        }
    }

    public class viewmodelss
    {
       public  List<Project> Projects { get; set; }

      public Project selectProject { get; set; }

        public viewmodelss()
        {
            Projects = new List<Project>();
            Projects.Add(new Project() { IsSelected = false });
            Projects.Add(new Project() { IsSelected = true });
            Projects.Add(new Project() { IsSelected = false });

            selectProject = (Project)Projects[1];
        }
        ICommand _command;

        public ICommand Command
        {
            get
            {
                if (_command == null)
                {
                    _command = new DelegateCommandTTs(CanExecute, Execute);
                }
                return _command;
            }
        }

        private void Execute(object parameter)
        {
            Project pj = (Project)parameter;
        }

        private bool CanExecute(object parameter)
        {
            return true;
        }

    }


    public class Project
    {
        public bool IsSelected { get; set; }

    }


    public class DelegateCommandTTs : ICommand
    {
        Predicate<object> canExecute;
        Action<object> execute;

        public DelegateCommandTTs(Predicate<object> _canexecute, Action<object> _execute)

            : this()
        {
            canExecute = _canexecute;
            execute = _execute;
        }

        public DelegateCommandTTs()
        {

        }

        public bool CanExecute(object parameter)
        {
            return canExecute == null ? true : canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            execute(parameter);
        }

    }


最好的问候,


Best Regards,

吕汉楠


这篇关于XAMLPARSEEXCEPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆