views:

95

answers:

1

I'm new to Silverlight/XAML/C# and havn't figured out all the concepts yet. I'm using the Accordion control together with some templates, the XAML looks like this:

<layoutToolkit:Accordion x:Name="MatchesAccordion" SelectionMode="ZeroOrMore" Width="Auto" SizeChanged="MatchesAccordion_SizeChanged">
    <layoutToolkit:Accordion.HeaderTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Path=Title}" TextWrapping="Wrap" />
        </DataTemplate>
    </layoutToolkit:Accordion.HeaderTemplate>

    <layoutToolkit:Accordion.ContentTemplate>
        <DataTemplate>
            <TextBox x:Name="ContentTextBox" Text="{Binding Path=Description}" TextWrapping="Wrap" VerticalAlignment="Stretch" IsReadOnly="True"/>
        </DataTemplate>
    </layoutToolkit:Accordion.ContentTemplate>
</layoutToolkit:Accordion>

This works well. But how would I go about connecting to an event (SizeChanged) on the Accordion.Content object?

A: 

If interested in the size changing of your TextBox (in the DataTemplate), you can literally just insert the name of the event you have in your code-behind file and it will work.

You'd have TextBox x:Name="ContentTextBox" SizeChanged="MyCodeBehind_SizeChanged_Event_Thing_Here" ...

However, if you're interested in the actual accordion Content changing size, you may need to use the VisualTreeHelper or another mechanism to jump into the visual tree, find the right item, and attach to that event. I'd recommend against this approach.

Jeff Wilcox