How can I create a button with multiple content values?
My goal is to create a button with two content values.
Think of a Scrabble tile as a button: it has a large letter in the center and a small number in the lower right corner. This is the effect I'm going to do.
I made a button that has two ContentPresenter objects and I gave each of the ContentPresenters a different style. However, I have not found a way to give each of the presenters a separate value (ie, if I set the button content to "X", then both ContentPresenters show "X", albeit in different styles).
How can I achieve my goal? I guess my approach is completely wrong ....
Bah ... I think I know what to do now. I have to make my own control, not change the button. It would be obvious to me if I was working in WinForms, but somehow all this Xaml makes me stupid.
Take a look at the ControlTemplate Expander sample at http://msdn.microsoft.com/en-us/library/ms753296.aspx
The extender is a subclass of HeaderedContentControl, it has two "contents": Header and Content
The control template has two ContentPresenter elements, ContentPresenter not bound to the default content property is defined as:
<ContentPresenter ContentSource = "Title" />
If you need to use a button and you don't want to add another property for the second content, you can use the attached property and the data binds the second ContentPresnter Content property to it.
I came up with creating a UserControl with multiple "content slots" here - it's better than getting a HeaderedControl since you are not limited in the number of slots.
Sample usage:
<Window x:Class="TkMVVMContainersSample.Services.TaskEditDialog.ItemEditView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Common="clr-namespace:TkMVVMContainersSample.Views.Common"
Title="ItemEditView"
>
<Common:DialogControl>
<Common:DialogControl.Heading>
<!-- Heading string goes here -->
</Common:DialogControl.Heading>
<Common:DialogControl.Control>
<!-- Concrete dialog content goes here -->
</Common:DialogControl.Control>
<Common:DialogControl.Buttons>
<!-- Concrete dialog buttons go here -->
</Common:DialogControl.Buttons>
</Common:DialogControl>
</Window>