簡體   English   中英

使用Interactive WPF時XAML錯誤

[英]Xaml error when using Interactivity wpf

使用Interactivity時出現以下錯誤:

錯誤集合屬性'System.Windows.Controls.Canvas'。'Triggers'為空。

這是我的代碼:

<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塊,否則無法看到設計器。

知道為什么嗎?

數據上下文如何連接到窗口/頁面? 建議將以下行添加到窗口/頁面並將IsDesignTimeCreatable設置為true:

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

這樣,視圖將在設計時綁定到視圖模型的值,這恰恰是應用程序中atm出問題的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM