1

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?

malte
  • 1,171
  • 1
  • 15
  • 28
  • http://stackoverflow.com/questions/20424662/how-to-change-the-background-color-of-message-box-in-wp8 – d.lavysh Dec 16 '13 at 16:28
  • @d.lavysh I've already read that link. I'm asking for the possibility to change the **Foreground** color! I know how to change the ForegroundColor for both (Caption and Message) together, but I'd like to have different colors for each of them. Do you have an idea / other link where this is explained? – malte Dec 16 '13 at 16:36
  • 2
    No I think you can't. This would break Wp8 design guidelines. If you need to do this for some reasons, you could create your own CustomMessageBox or you download the [sources](http://phone.codeplex.com/SourceControl/latest) and add dependency properties for caption and content text and borders. – dixus Dec 16 '13 at 18:28
  • Hi, Is there a simple way to change the ForegroundColor for both (Caption and Message) together? – Samy S.Rathore Aug 28 '14 at 08:01

1 Answers1

2

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.)

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • This looks like a great approach I should've thought myself of. However, my template seems not to be recognized/used. Do I have to reference it in any special way? – malte Dec 17 '13 at 08:17
  • Forget it. Great thing. Working like charm. I just changed "Title" and it did not work, but I wanted to change "Caption" and because I had no title, nothing changed ... great story, huh? 30minutes of my life wasted with this ... THANKS for your help! :) – malte Dec 17 '13 at 15:44