1 Results for 'ask Microsoft'

  1. 2009.06.11 Behaviors make me depressed. (1)
I posted how to use DataBinding with Behaviors in Silverlight 3 recently. However, it turns out, it's impossible or very limitted.

Follow code is what I expected to work.

<Grid x:Name="LayoutRoot" Background="White">
    <Button Content="Test" HorizontalAlignment="Right">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <hi:ShowMessageBoxAction x:Name="Action1"/>
            </i:EventTrigger>
        </i:Interaction.Triggers

        <i:Interaction.Behaviors>
            <hi:BindingProxyBehavior
                        TargetName="Action1"
                        TargetPropertyName="Message"
                        Binding="{Binding Path=MockString}" />
        </i:Interaction.Behaviors>
    </Button>
</Grid>

[It doesn't work, 'cause Behaviors are not FrameworkElements]

- ShowMessageBoxAction which named "Action1" by x:Name attribute has a property named Message.
- BindingProxyBehavior is a Behavior. And it figures out "Action1" by AssociatedObject(LayoutRoot).FindName method when it has been invoked.

But It's impossible, 'cause Behaviors are not Frameworks so they can't be found by FrameworkElement.FindName method.

It's OK, I can understand why is it impossible. However how do you think about code follow:

<DataTemplate x:Key="DataTemplate1">
    <Grid>
        <Button HorizontalAlignment="Left" Content="{Binding Mode=OneWay, Path=Title}">
            <i:Interaction.Triggers>
                <i:EventTrigger x:Name="Trriger1" EventName="Click">
                    <hi:ShowMessageBoxAction x:Name="ShowMessageAction"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>           

            <i:Interaction.Behaviors>
                <hi:BindingProxyBehavior
                    TargetName="ShowMessageAction"
                    TargetPropertyName="Message"
                    Binding="{Binding Path=Description}" />
            </i:Interaction.Behaviors>
        </Button>
    </Grid>
</DataTemplate>

[Does it work or not?]

It's similar to first one, except root Grid is in the DataTemplate.
Guess what? it works. Very well.
HOW COME!? Isn't it wierd?

Now I have to give up to do DataBinding with Behaviors in Silverlight 3 by that way.
It makes me depressed. "No binding, more work".
Anyway all I really want to ask Microsoft is, just allow us DataBinding with Behaviors, so we can create application rapidly, design-friendly, and even elegantly! Like follow code:

<Grid x:Name="LayoutRoot">
    <Button Content="Test">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <hi:ShowMessageBoxAction
                    x:Name="Action1"
                    Message="{Binding Path=Description}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>
</Grid>

[Elegant DataBinding with Behaviors]

Here for sample project:

Posted by gongdo

Submit comment.

  1. Favicon of http://www.moncleroutletespain.com/ BlogIcon moncler chaquetas 2013.01.04 12:42  comment URL  Edit/Remove  Submit comment.

    Traditionally, http://www.moncleroutletespain.com/ moncler españa, most Australian businesses have a corporate travel policy that allows some flexibility and is enforced at the will of each staff member. However, as the economic downturn continues, BCD Travel is receiving an increasing number of requests from its business travel clients to introduce new, http://www.moncleroutletespain.com/ moncler online, non-negotiable restrictions on their individual booking profiles on the BCD Travel booking system, http://www.moncleroutletespain.com/ moncler.BCD Travel, http://www.moncleroutletespain.com/ http://www.moncleroutletespain.com/?s booking system allows each business travel client to have their own booking profile containing their preferred suppliers, http://www.moncleroutletespain.com/ moncler chaquetas, negotiated rates and other preferences, such as when first class flights are allowed. Corporate travel clients are able to apply as many restrictions as they like to their profile to ensure their staff comply with their company?s internal business travel policy, http://www.moncleroutletespain.com/ moncler outlet.Related articles:


    http://jaystrange.tistory.com/624 http://jaystrange.tistory.com/624

    http://taeheeh.tistory.com/452?apppush http://taeheeh.tistory.com/452?apppush