简体   繁体   中英

Xaml error when using Interactivity wpf

I'm getting a the following error when I use Interactivity :

Error Collection property 'System.Windows.Controls.Canvas'.'Triggers' is null.

Here's my code:

<ItemsControl x:Name="StreamCanvasItemSource" ItemsSource="{Binding StreamCanvasItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=StreamImage}" Height="{Binding ActualHeight, ElementName=StreamImage}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas x:Name="StreamCanvas" Background="Transparent" Width="{Binding ActualWidth, ElementName=StreamImage}" Height="{Binding ActualHeight, ElementName=StreamImage}" 
                AuxiliaryUtils:SizeObserver.Observe="True" AuxiliaryUtils:SizeObserver.ObservedWidth="{Binding CurrentCanvasWidth, Mode=OneWayToSource}" 
                AuxiliaryUtils:SizeObserver.ObservedHeight="{Binding CurrentCanvasHeight, Mode=OneWayToSource}" 
                AuxiliaryUtils:SizeObserver.ObservedLeft="{Binding CanvasLeft, Mode=OneWayToSource}" AuxiliaryUtils:SizeObserver.ObservedTop="{Binding CanvasTop, Mode=OneWayToSource}">
                <Interactivity:Interaction.Triggers>
                    <Interactivity:EventTrigger EventName="PreviewMouseWheel">
                        <Command:EventToCommand Command="{Binding OnMouseWheelCommand}" PassEventArgsToCommand="True" />
                    </Interactivity:EventTrigger>
                    <Interactivity:EventTrigger EventName="PreviewMouseDown">
                        <Interactivity:InvokeCommandAction Command="{Binding OnMouseDownCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}"/>
                    </Interactivity:EventTrigger>
                    <Interactivity:EventTrigger EventName="PreviewMouseMove">
                        <Interactivity:InvokeCommandAction Command="{Binding OnMouseMoveCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}"/>
                    </Interactivity:EventTrigger>
                    <Interactivity:EventTrigger EventName="PreviewMouseUp">
                        <Interactivity:InvokeCommandAction Command="{Binding OnMouseUpCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}"/>
                    </Interactivity:EventTrigger>
                </Interactivity:Interaction.Triggers>
            </Canvas>
        </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ItemsControl>

The thing is that everything works as expected when I run the program, I see the error when compiling, and I can't see the designer unless I comment the Interactivity block.

Any idea why?

How is the datacontext connected to the window/page? it would it advisable to add the following line to the window/page and setting IsDesignTimeCreatable to true:

d:DataContext="{d:DesignInstance Type=yourviewmodetype, IsDesignTimeCreatable=True}"

In this way the view will bind to the values of the viewmodel in designtime which is exactly what is going wrong atm in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM