WPF 4.0 InvokeCommandAction兼容性(System.Windows.Interactivity) [英] WPF 4.0 InvokeCommandAction Compatibility (System.Windows.Interactivity)

查看:1244
本文介绍了WPF 4.0 InvokeCommandAction兼容性(System.Windows.Interactivity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF 4.0中插入InvokeCommandAction(Blend 4 SDK)时遇到问题。用户控件不显示,我有一些例外。 (登录底部)
没有我的xaml代码中的行,没有问题(但没有事件触发器)。



我测试了这部分代码在外部光项目,它的工作完美!
可能InvokeCommandAction与may应用程序中的某些内容不兼容,但是什么?

 < UserControl x:Class = Project.Views.Menu.TestView
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:Menu =clr-namespace: ViewModels.Menu
mc:Ignorable =d
x:Name =test
d:DesignHeight =300d:DesignWidth =300>

< UserControl.DataContext>
< Menu:TestViewModel />
< /UserControl.DataContext>
< Grid>
< ListBox x:Name =listBoxWidth =200
MaxHeight =128SelectionMode =SingleMargin =0>
< i:Interaction.Triggers>
< i:EventTrigger EventName =SelectionChanged>
< i:InvokeCommandAction Command ={Binding TestCommand,Mode = OneWay}CommandParameter ={Binding SelectedItem,ElementName = listBox}/>
< / i:EventTrigger>
< / i:Interaction.Triggers>
<&ListBoxItem的GT; blabla1< / ListBoxItem的>
< ListBoxItem> blabla2< / ListBoxItem>
< ListBoxItem> blabla3< / ListBoxItem>
< ListBoxItem> blabla4< / ListBoxItem>
< / ListBox>
< / Grid>
< / UserControl>






我已经登录的错误,但我不'不懂:

 

错误2011-07-26 15点18分47秒 - 拉提及此战争D'OBJET n'est PAS définieàune instance d'un objet。
PresentationFramework
A System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader,XamlObjectWriter的XamlWriter,布尔onlyLoadOneNode,布尔skipJournaledProperties,布尔shouldPassLineNumberInfo,IXamlLineInfo xamlLineInfo,IXamlLineInfoConsumer xamlLineInfoConsumer,XamlContextStack`1栈,IStyleConnector styleConnector)
A System.Windows.Markup.WpfXamlLoader.Load(xamlReader xamlReader,IXamlObjectWriterFactory writerFactory,布尔skipJournaledProperties,对象rootObject,XamlObjectWriterSettings设置,开放的基本URI)
A System.Windows.Markup.WpfXamlLoader.LoadBaml(xamlReader xamlReader,布尔skipJournaledProperties,对象rootObject,XamlAccessLevel ACCESSLEVEL,乌里基本URI)
A System.Windows.Markup.XamlReader.LoadBaml(流流,ParserContext parserContext,对象的父母,布尔closeStream)
A System.Windows.Application。 LoadComponent(对象组件,乌里resourceLocator)
A Project.Views.Menu.TestView.InitializeComponent()丹斯C:\Project\Views\Menu\TestView.xaml:LIGNE 1
项目.Views.Menu.TestView..ctor()丹斯C:\Project\Views\Menu\TestView.xaml.cs:LIGNE 24
A Project.ViewModels.MainWindowsViewModel..ctor()丹斯ç :\Project\ViewModels\MainWindowsViewModel.cs:ligne 52

错误2011-07-26 15:18:47 - Une exception aétélevéepar la cible d'un appel。
mscorlib程序
A System.RuntimeTypeHandle.CreateInstance(RuntimeType型,布尔publicOnly,布尔NOCHECK,布尔和canBeCached,RuntimeMethodHandleInternal和构造函数,布尔和bNeedSecurityCheck)
A System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis布尔fillCache)
A System.RuntimeType.CreateInstanceDefaultCtor(布尔publicOnly,布尔skipVisibilityChecks,布尔skipCheckThis,布尔fillCache)
A System.Activator.CreateInstance(类型类型,布尔非公开)
系统.RuntimeType.CreateInstanceImpl(的BindingFlags bindingAttr,粘结剂粘合,对象[] ARGS,CultureInfo的文化,对象[] activationAttributes)
A System.Activator.CreateInstance(类型类型,的BindingFlags bindingAttr,粘结剂粘合,对象[] ARGS,CultureInfo的文化,Object [] activationAttributes)
àSystem.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object [] arguments)
àMS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType,Object [] args)
àMS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType,Object [] args)
àSystem.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
àSystem。 Xaml.XamlObjectWriter.WriteEndObject()
A System.Xaml.XamlWriter.WriteNode(XamlReader读卡器)
A System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader,XamlObjectWriter的XamlWriter,布尔onlyLoadOneNode,布尔skipJournaledProperties,布尔shouldPassLineNumberInfo,IXamlLineInfo xamlLineInfo,IXamlLineInfoConsumer xamlLineInfoConsumer,XamlContextStack`1栈,IStyleConnector styleConnector)
A System.Windows.Markup.WpfXamlLoader.Load(xamlReader xamlReader,IXamlObjectWriterFactory writerFactory,布尔skipJournaledProperties,对象rootObject,XamlObjectWriterSettings设置,乌里基本URI)
A System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader,布尔skipJournaledProperties,对象rootObject,XamlAccessLevel ACCESSLEVEL,乌里基本URI)
A System.Windows.Markup.XamlReader.LoadBaml(流流,parserContext parserContext ,Object parent,Boolean closeStream)
àSystem.Windows.Application.LoadComponent(Object component,Uri resourceLocator)
àProject.MainWindow.InitializeComponent()dans C:\Project\MainWindow.xaml: ligne 1
àProject.MainWindow..ctor()dans C:\Project\MainWindow.xaml.cs:ligne 17


错误2011-07-26 15 :18:47 - Une exception aétélevéepar la cible d'un appel。
mscorlib程序
A System.RuntimeTypeHandle.CreateInstance(RuntimeType型,布尔publicOnly,布尔NOCHECK,布尔和canBeCached,RuntimeMethodHandleInternal和构造函数,布尔和bNeedSecurityCheck)
A System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis ,Boolean fillCache)
àSystem.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,Boolean skipVisibilityChecks,Boolean skipCheckThis,Boolean fillCache)
àSystem.Activator.CreateInstance(Type type,Boolean nonPublic)
àSystem .RuntimeType.CreateInstanceImpl(的BindingFlags bindingAttr,粘结剂粘合,对象[] ARGS,CultureInfo的文化,对象[] activationAttributes)
A System.Activator.CreateInstance(类型类型,的BindingFlags bindingAttr,粘结剂粘合,对象[] ARGS,CultureInfo的文化,Object [] activationAttributes)
àSystem.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object [] arguments)
àMS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType,Object []参数)
A MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType,对象[]参数)
A System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext CTX)
的系统。 Xaml.XamlObjectWriter.WriteStartMember(XamlMember属性)
A System.Xaml.XamlWriter.WriteNode(XamlReader读卡器)
A System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader,XamlObjectWriter的XamlWriter,布尔onlyLoadOneNode,布尔skipJournaledProperties,布尔shouldPassLineNumberInfo,IXamlLineInfo xamlLineInfo,IXamlLineInfoConsumer xamlLineInfoConsumer,XamlContextStack`1栈,IStyleConnector styleConnector)
A System.Windows.Markup.WpfXamlLoader.Load(xamlReader xamlReader,IXamlObjectWriterFactory writerFactory,布尔skipJournaledProperties,对象rootObject,XamlObjectWriterSettings设置,乌里基本URI)
A System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader,布尔skipJournaledProperties,对象rootObject,XamlAccessLevel ACCESSLEVEL,乌里基本URI)
A System.Windows.Markup.XamlReader.LoadBaml(流流, ParserContext parserContext,对象的父母,布尔closeStream)
A System.Windows.Application.LoadBamlStreamWithSyncInfo(流流,ParserContext PC)
A System.Windows.Application.LoadComponent(URI resourceLocator,布尔bSkipJournaledProperties)
A System.Windows.Application.DoStartup()
A System.Windows.Application.b__1(对象未用)
A System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表回调,对象指定参数时,的Int32 numArgs )
A MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,委托方法,对象指定参数时,的Int32 numArgs,代表catchHandler)


解决方案

您的InteractionTrigger应该看起来更像这样:

 < i:Interaction .Triggers> 
< i:EventTrigger EventName =SelectionChanged>
< I:InvokeCommandAction命令={结合DataContext.TestCommand,的ElementName =测试}CommandParameter ={结合的SelectedItem,的ElementName =列表框}/>
< / i:EventTrigger>
< / i:Interaction.Triggers>

希望我不太晚=)


I have a problem when I insert a InvokeCommandAction (Blend 4 SDK) in WPF 4.0. The usercontrol is not displayed and I've got some exceptions. (log on bottom) Without the line in my xaml code, there is no problem (but no event trigger).

I have tested this part of code in an external light project, and it's work perfectly !! Maybe InvokeCommandAction is not compatible with something in may app, but what ?

<UserControl x:Class="Project.Views.Menu.TestView"
             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:Menu="clr-namespace:Project.ViewModels.Menu" 
             mc:Ignorable="d" 
             x:Name="test"
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.DataContext>
        <Menu:TestViewModel />
    </UserControl.DataContext>
    <Grid>
        <ListBox x:Name="listBox" Width="200" 
                    MaxHeight="128" SelectionMode="Single" Margin="0">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding TestCommand, Mode=OneWay}" CommandParameter="{Binding SelectedItem, ElementName=listBox}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>    
            <ListBoxItem>blabla1</ListBoxItem>
            <ListBoxItem>blabla2</ListBoxItem>
            <ListBoxItem>blabla3</ListBoxItem>
            <ListBoxItem>blabla4</ListBoxItem>
        </ListBox>
    </Grid>
</UserControl>


I have logged that errors, but I don't understand:


ERROR 2011-07-26 15:18:47 – La référence d'objet n'est pas définie à une instance d'un objet.
PresentationFramework
   à System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   à System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   à System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   à System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   à System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   à Project.Views.Menu.TestView.InitializeComponent() dans C:\Project\Views\Menu\TestView.xaml:ligne 1
   à Project.Views.Menu.TestView..ctor() dans C:\Project\Views\Menu\TestView.xaml.cs:ligne 24
   à Project.ViewModels.MainWindowsViewModel..ctor() dans C:\Project\ViewModels\MainWindowsViewModel.cs:ligne 52

ERROR 2011-07-26 15:18:47 – Une exception a été levée par la cible d'un appel.
mscorlib
   à System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   à System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   à System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   à System.Activator.CreateInstance(Type type, Boolean nonPublic)
   à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
   à System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   à System.Xaml.XamlObjectWriter.WriteEndObject()
   à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   à System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   à System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   à System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   à System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   à System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   à Project.MainWindow.InitializeComponent() dans C:\Project\MainWindow.xaml:ligne 1
   à Project.MainWindow..ctor() dans C:\Project\MainWindow.xaml.cs:ligne 17


ERROR 2011-07-26 15:18:47 – Une exception a été levée par la cible d'un appel.
mscorlib
   à System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   à System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   à System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   à System.Activator.CreateInstance(Type type, Boolean nonPublic)
   à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
   à System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   à System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
   à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   à System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   à System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   à System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   à System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   à System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   à System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   à System.Windows.Application.DoStartup()
   à System.Windows.Application.b__1(Object unused)
   à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   à MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

解决方案

Your InteractionTrigger should look more like this:

        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding DataContext.TestCommand, ElementName=test}" CommandParameter="{Binding SelectedItem, ElementName=listBox}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers> 

Hope i'm not too late =)

这篇关于WPF 4.0 InvokeCommandAction兼容性(System.Windows.Interactivity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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