7

我一直在尝试在 wpf 窗口上实现行为,因此我在当前解决方案中添加了对 System.Winodws.Interactivity 的引用,然后编写了所需的行为。但为了应用此行为,我必须在 Windows XAML 中编写类似的内容。

<Window x:Class="WpfApplication5.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" Height="350" Width="525" 
        xmlns:behav ="clr-namespace:WpfApplication5" 
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity;assembly=System.Windows.Interactivity">
    <Window.Resources>
        <i:Interaction.Behaviors>
            <behav:DialogIconRemoveBehavior></behav:DialogIconRemoveBehavior>
        </i:Interaction.Behaviors>
    </Window.Resources>
    <Grid>

    </Grid>
</Window>

但这不是有效的标签,因为我可能必须添加对除 System.Windows.Interactivity 之外的任何其他程序集的引用,所以,请建议我还需要做什么才能在 XAML 中使用标签

4

1 回答 1

9

在浪费了我一小时之后,我才知道只有我必须包含 System.Windows.Interactivity 作为参考并且我已经完成了。

问题是不能在任何控件的资源部分中声明行为。

我采取以下的那一刻

<i:Interaction.Behaviors>

</i:Interaction.Behaviors>

没有资源然后它工作得很好。

所以,结论只有 System.Windows.Interacivity 是唯一需要的。

永远不要在资源或样式中声明该行为部分。

于 2013-09-13T07:51:26.577 回答