0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

型 'EventToReactiveCommand' の値は、型 'TriggerActionCollection' のコレクションまたは辞書に追加できません。

Last updated at Posted at 2020-06-19

エラーメッセージ

型 'EventToReactiveCommand' の値は、型 'TriggerActionCollection' のコレクションまたは辞書に追加できません。

への対処。
System.Windows.Window.InteractivityではなくMicrosoft.Xaml.Behaviors.Wpfを使いましょう。

理由はこの辺みたいです。

WPF のビヘイビアーが入ってる Blend SDK for Visual Studio が Visual Studio 2019 で消えた件について

EventToReactiveCommandを使おうとしたけど例外!!

MVVM でイベント引数の値を ViewModel のコマンドに渡す方法を参考にやってみたらタイトルの例外で落ちてしまいました。

検索してみたら冒頭の情報とTwitterに辿り着きossの方のInteractivityを使うようにしたらすっと動きました。
地味に時間かかって悔しい。

具体的にはこんな感じです。

<Window x:Class="TestEventToReactiveCommand.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://prismlibrary.com/"

        xmlns:behaviours="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:interactivity="clr-namespace:Reactive.Bindings.Interactivity;assembly=ReactiveProperty.WPF"
        
        xmlns:local="clr-namespace:TestEventToReactiveCommand"
        prism:ViewModelLocator.AutoWireViewModel="True"
        Title="{Binding Title}" Height="350" Width="525">

    <behaviours:Interaction.Triggers>
        <behaviours:EventTrigger EventName="MouseMove">
            <interactivity:EventToReactiveCommand Command="{Binding MouseMoveCommand}">
                <local:MouseMoveToMousePositionConverter />
            </interactivity:EventToReactiveCommand>
        </behaviours:EventTrigger>
    </behaviours:Interaction.Triggers>

    <Grid>
        <ContentControl prism:RegionManager.RegionName="ContentRegion" />
        <TextBlock
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Text="{Binding Message.Value}" />
    </Grid>
</Window>

なんか私の場合はNugetで Microsoft.Xaml.Behaviors.Wpf を追加しないでも動いてますが、
ここによれば追加しろと書いてある??

ざっと動かしただけですが確認したソース
TestEventToReactiveCommand

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?