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

1

8

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

Questioning answered 13/9, 2013 at 4:46 Comment(0)
Q
10

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.

Questioning answered 13/9, 2013 at 7:51 Comment(1)
As of 2019, see this and note the namespace is now http://schemas.microsoft.com/xaml/behaviors (previously, like in your question: http://schemas.microsoft.com/expression/2010/interactivity)Whitecollar

© 2022 - 2024 — McMap. All rights reserved.