Text align problem with RADMessageBox.

2 posts, 0 answers
  1. Saurav
    Saurav avatar
    2 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2013 Link to this post

    Hello, I am trying to create a 3 button messageBox using RADMessageBox in my Windows Phone project. When I use two buttons, the button content or label is automatically centre aligned. However, when I give three buttons than text is left aligned. How do I align text to centre?

    I have attached an example of what I get and what is expected.

    Expected

    What I get

    One method I know is to make a custom control template but is there another way already specified in RADMessageBox which can let me do this?

  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 02 Sep 2013 Link to this post

    Hello Saurav,

    Thank you for contacting us. Indeed, this scenario can be achieved through the usage of a custom ControlTemplate.

    <UserControl.Resources>
        <ControlTemplate x:Key="ImageTemplate" TargetType="telerikMessageBox:RadMessageBoxControl">
            <Border Padding="12" Background="{StaticResource PhoneChromeBrush}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <ContentControl x:Name="PART_Title" HorizontalContentAlignment="Left"
                            FontSize="{StaticResource PhoneFontSizeLarge}"
                            FontFamily="{StaticResource PhoneFontFamilySemiBold}" Margin="{StaticResource PhoneMargin}" />
                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                        <Image Source="idjits.jpg" Margin="12, 12, 0, 24" />
                        <ContentControl HorizontalContentAlignment="Left" VerticalContentAlignment="Top"
                                x:Name="PART_Message" Margin="12, 12, 12, 24" />
                    </StackPanel>
                    <CheckBox x:Name="PART_CheckBox" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
                    <ContentControl Grid.Row="3" x:Name="PART_ButtonsContainer" HorizontalContentAlignment="Stretch"
                            HorizontalAlignment="Stretch" Margin="12 0" Width="440">
                        <ContentControl.ContentTemplate>
                            <DataTemplate>
                                <StackPanel x:Name="PART_ButtonsPanel" Loaded="PART_ButtonsPanel_Loaded" />
                            </DataTemplate>
                        </ContentControl.ContentTemplate>
                    </ContentControl>
                </Grid>
            </Border>
        </ControlTemplate>
    </UserControl.Resources>

    public Playground()
    {
        InitializeComponent();
        ControlTemplate imageTemplate = (ControlTemplate)this.Resources["ImageTemplate"];
        RadMessageBox.Show(imageTemplate, "Title", new string[] { "yes", "no", "maybe" });
    }
     
    private void PART_ButtonsPanel_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        var panel = sender as StackPanel;
        foreach (var item in panel.Children)
        {
            Button button = (Button)item;
            button.Width = double.NaN;
            button.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
        }
    }

    Let me know how it goes. 

    Regards,
    Kiril Stanoev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top