views:

273

answers:

4

I want to make buttons similar to those on this website.

Lets say that the object I'm working with is ArtPiece, and has a Title and Date. I want both of those to show up on my buttons in two different TextBlocks.

I've been trying to modify the button's ContentTemplate, then modifying the button's ContentPresenter inside the ContentTemplate, but I still can't get the TextBlocks to bind.

Any help getting this done entirely in XAML? I'm using Expression 3.

A: 

It sounds like what you really want is some sort of multi-binding support to bind these two properties to one Content property on the button. As far as I know there is no built in multi-binding support in silverlight as there is in WPF. This article outlines one approach to implementing it in silverlight.

If you were using the MVVM pattern a much easier approach would be to create another property in your ViewModel which concatenated the two strings together and then you could just bind the Content of the button to that single new property. This would be a much simpler and cleaner approach in my opinion.

Dan Auclair
+2  A: 

You want to do something like this:

        <Button Click="Button_Click" Name="button" >
            <Button.ContentTemplate>
                <DataTemplate>
                    <StackPanel Background="Yellow" Width="200" Height="200">
                        <TextBlock Text="{Binding Title}" />
                        <TextBlock Text="{Binding Date}" />
                    </StackPanel>
                </DataTemplate>
            </Button.ContentTemplate>
        </Button>
KeithMahoney
Can't believe it was that simple. I thought I had tried that before, oh well.
MStodd