1

使用时出现以下错误Interactivity

错误集合属性“System.Windows.Controls.Canvas”。“触发器”为空。

这是我的代码:

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

Interactivity问题是当我运行程序时一切都按预期工作,我在编译时看到错误,除非我评论该块,否则我看不到设计器。

知道为什么吗?

4

1 回答 1

0

数据上下文如何连接到窗口/页面?建议将以下行添加到窗口/页面并将 IsDesignTimeCreatable 设置为 true:

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

通过这种方式,视图将在设计时绑定到视图模型的值,这正是您的应用程序中出现问题的地方。

于 2018-02-21T11:00:56.120 回答