<i: Interaction.Behavior> option is not coming for applying beahviour

孤街浪徒 提交于 2019-12-06 01:33:53

问题


I have been trying to implement a behavior on a wpf window therefore I have added reference to System.Winodws.Interactivity in my current solution and then wrote the desired behavior. but in order to apply this behavior, I have to write something like this in 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>

but this is not valid tag because I might have to add reference to any other assembly apart form System.Windows.Interactivity, So, please suggest what else I have to do in order to use tag in XAML


回答1:


After wasting my one hour I came to know that only I had to include System.Windows.Interactivity as reference and which I had already done.

the issue was that Behaviors can not be declared in the Resource part of any control.

the moment I took the following

<i:Interaction.Behaviors>

</i:Interaction.Behaviors>

out of the resources then it worked fine.

So, conclusion only System.Windows.Interacivity is the only required.

Never declare that behavior part in the resources or style.



来源:https://stackoverflow.com/questions/18778490/i-interaction-behavior-option-is-not-coming-for-applying-beahviour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!