Is there a way to define different foreground colors in my CustomMessageBox from WindowsPhone 8 Toolkit?

317 views Asked by At

I was wondering, whether it is possible to style the CustomMessageBox from Windows Phone 8 Toolkit more precisely?

In this case, I'd like to have different foreground colors for the Caption and for the actual Message / the button text/border.

Can I define the Box in XAML as well?

1

There are 1 answers

2
McGarnagle On BEST ANSWER

It should not be too much effort. All you have to do is subclass CustomMessageBox, add dependency properties for the separate foreground colors, and then modify the default control template. (You will see that default template uses the same Foreground property for the title, caption, message, and button.)

As an example, let's take the title color. First add a dependency property:

public class ExtendedCustomMessageBox : CustomMessageBox
{
    public Brush TitleForeground
    {
        get { return (Brush)GetValue(TitleForegroundProperty); }
        set { SetValue(TitleForegroundProperty, value); }
    }
    public static readonly DependencyProperty TitleForegroundProperty =
        DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(ExtendedCustomMessageBox), null);

    public CustomMessage()
        : base()
    {
        DefaultStyleKey = typeof(CustomMessageBox);
    }
}

Now modify the appropriate part of the control template. Use a TemplateBinding to reference the new property:

<TextBlock 
    x:Name="TitleTextBlock"
    Text="{TemplateBinding Title}" 
    Foreground="{TemplateBinding TitleForeground}"
    Visibility="Collapsed"
    Margin="24,16,24,-6"
    FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>

(Note that you can find the full control template in the WP8 toolkit download, in the file Themes\Generic.xaml. Just copy-paste into your project's resources, and modify.)