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

Yogesh picture Yogesh · Sep 13, 2013 · Viewed 16.3k times · Source

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

Answer

Yogesh picture Yogesh · Sep 13, 2013

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.