views:

24

answers:

0

I have a control in which I am creating a specific Command class in XAML, and it needs a reference to a ContentControl element that is declared later in the XAML. I have the relevant property of the command object bound to the ContentControl via its ElementName, but at runtime, it doesn't seem to get the ContentControl (the command's property is null). At first, I thought this had something to do with the ContentControl's placement later in the XAML, but I tried putting the ContentControl before the command, and had the same issue. Now I'm wondering if it has something to do with the fact that the command object is being created inside an object that is a member of an attached property on an element. Perhaps some code would be clearer:

<Expander HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.RowSpan="2" x:Name="expander" 
                                ExpandDirection="Right">
            <Common:CommandEvents.CommandEvents>
                <Common:CommandEventHookup EventName="Expanded" x:Name="expandedHookup">
                    <Common:CommandEventHookup.Command>
                        <Commands:ExpandFilterToolbarCommand ContentPanel="{Binding ElementName=contentPanel}"
                                                             ExpandedContent="{StaticResource buttonPanel}" />
                    </Common:CommandEventHookup.Command>
                </Common:CommandEventHookup>
                <Common:CommandEventHookup EventName="Collapsed">
                    <Common:CommandEventHookup.Command>
                        <Commands:CollapseFilterToolBarCommand ContentPanel="{Binding ElementName=contentPanel}"
                                                               CollapsedContent="{StaticResource collapsedText}" />
                    </Common:CommandEventHookup.Command>
                </Common:CommandEventHookup>
            </Common:CommandEvents.CommandEvents>
        </Expander>



        <ContentControl VerticalAlignment="Top" VerticalContentAlignment="Bottom"
                    Width="200" x:Name="contentPanel" Grid.Column="1" Content="{StaticResource collapsedText}" Margin="3,0,0,0" />

'Common:CommandEvents.CommandEvents' is an attached property that is a collection of CommandEventHookup objects.

Any idea why the ContentPanel property of the commands would be null?