1

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?

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Idanis
  • 1,918
  • 6
  • 38
  • 69
  • 1
    Read [this](https://stackoverflow.com/questions/43640361/does-mvvm-stop-the-ability-for-the-visual-studio-designer-to-show-xaml/43642741#43642741) plz. – Thomas V Feb 21 '18 at 10:16

1 Answers1

0

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.

Thomas V
  • 151
  • 14