XAML 交互性和交互的编译错误

6tqwzwtp  于 2023-05-11  发布在  其他
关注(0)|答案(2)|浏览(345)

我试图执行下面的xaml代码,它引用了交互性和交互,如图所示,我不断得到错误。
下面附上了xaml代码,并在出现错误的地方给出了注解。

<Grid 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions">

    <Popup x:Name="popup" PlacementTarget="{Binding ElementName=imageList}">
        <Image Source="{Binding PlacementTarget.SelectedItem , ElementName=popup}"/>
    </Popup>
    <ListView x:Name="imageList" >
        <i:Interaction.Triggers>  //ERROR
            <i:EventTrigger EventName="SelectionChanged"> //ERROR
                <ei:ChangePropertyAction PropertyName="IsOpen" 
                    TargetName="{Binding ElementName=popup}" Value="True"/> //ERROR
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ListView>
</Grid>

我想在新窗口中显示所选图像。但会出现以下错误。

nimxete2

nimxete21#

您需要添加引用(Visual Studio中的Project->Add Reference->Assemblies)到System.Windows.Interactivity.dllMicrosoft.Expressions.Interactions.dll
它们是Blend SDK的一部分,可以从microsoft.com下载或通过安装this NuGet package(工具->Nuget包管理器->包管理器控制台)到您的项目中。

mm5n2pyu

mm5n2pyu2#

在使用Elmish.WPF project's C# Sample project 'NewWindow'.时遇到相同的错误解决方案可在此StackOverflow Q&A中找到:Interaction triggers inside DataTemplate not working with XamlReader
我的回答是:

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

...到顶部的XAML页面的定义。然后添加Nuget包Microsoft.Xaml.Behaviors.Wpf(我正在处理一个WPF项目,您可能只需要Microsoft.Xaml.Behaviors)。

相关问题