Skip to main content

Microsoft Silverlight

Put controls in another UserControl (hmm, strange subject, but read the message instead :-)RSS Feed

(0)

hehrsson
hehrsson

Member

Member

26 points

71 Posts

Put controls in another UserControl (hmm, strange subject, but read the message instead :-)

Hi.

In our business application we have several UserControls that displays different lists of data.
The controls are basicly made up of a DataGrid and some filter controls and buttons.
The design of these UserControls are pretty much the same, only the DatGrid columns and the data differs.
So, I have created a UserControl which is used as a footer in the UserControls.
The footer contains some standard buttons, status images and text messages.

Now to the question, some of the UserControls that implements this footer have their own special buttons that I want to add to the footers collection of buttons.
How can I, in XAML add a button to another UserControl.
I pretty much would like something similar to the DataGrid where you can add a collection of Columns for example.

My footer control have a StackPanel which contains the standard buttons that all grid controls use, I want to add another StackPanel that can host "extended buttons" that can be added from the control that hosts the footer.

I tried to make a collection of buttons and a StackPanel in the footer:

public
Collection<HyperlinkButton> ExtendedButtons { get; set; }

<StackPanel Orientation="Horizontal" x:Name="ExtendedButtonPanel" Grid.Column="1" HorizontalAlignment
="Right" />

In the host control I tried this:
<grid:GridFooter x:Name="Footer" Grid.Row="2" ShowSaveButton
="False">
  <grid:GridFooter.ExtendedButtons
>
    <HyperlinkButton x:Name="ButtonSearchExternal" VerticalAlignment="Center" Click
="ButtonSearchExternal_Click">
      <StackPanel Orientation
="Horizontal">
        <Image Source="../img/24/find.png" Style="{StaticResource Default_Image
}" />
        <TextBlock x:Name="ButtonSearchExternalLabel" VerticalAlignment="Center" Margin="5,0,0,0" Foreground
="Black" />
      </StackPanel
>
    </HyperlinkButton
>
  </grid:GridFooter.ExtendedButtons
>
</grid:GridFooter
>

But this will generate an AG_E_PARSER_BAD_PROPERTY_VALUE error in runtime.

I also tried to create a StackPanel with the buttons in the host control, and then tried to add those to the StackPanel in the footer control in code behind, but with no luck.

Is there a better way to do this? The best solution for me would be to specify it in XAML in someway like my first example, just add one or several HyperlinkButtons.

Regards,
Håkan

 

meykih
meykih

Participant

Participant

876 points

213 Posts

Re: Put controls in another UserControl (hmm, strange subject, but read the message instead :-)

Maybe you could try to declare your ExtendedButtons as an ObservableColletion just like the columns-property of a datagrid.

Regards,
Maike Ohlig

Please mark post as answer if it helped you

hehrsson
hehrsson

Member

Member

26 points

71 Posts

Re: Put controls in another UserControl (hmm, strange subject, but read the message instead :-)

Still the same parser error :-(

/Håkan

hehrsson
hehrsson

Member

Member

26 points

71 Posts

Re: Put controls in another UserControl (hmm, strange subject, but read the message instead :-)

No other solution for my problem?

Shortly described:
I have a UserControl with a StackPanel.
The UserControl is hosted within another UserControl. From this "host control" I want to add content (HyperlinkButtons) in the StackPanel of the "child control".
Preferrably I would like to add it directly in XAML, kinda like you add columns to a DataGrid or RowDefinitions to a Grid.
Second best would be to att it in the code behind.

See my first post at the top for a more detailed description.

Regards
Håkan

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities