RadMessagebox with controltemplate, text does not wrap

6 posts, 1 answers
  1. Ove
    Ove avatar
    9 posts
    Member since:
    May 2011

    Posted 17 Oct 2011 Link to this post

    Hello

    When using the sample in the documentation with a ControlTemplate for the RadMessageBox and using a large message, it does not wrap the text, it is only shown on one line. How can I make the message wrap so that i can see the complete message?
    /Thanks Ove

  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 Oct 2011 Link to this post

    Hi Ove,

     Thank you for the question.
    This is a direct result of the ContentControl that is used to display the message.
    Since you are using a custom ControlTemplate you can change the ContentControl for the message like this:

    <ContentControl x:Name="PART_Message"
                    Content="Some content">
        <ContentControl.Template>
            <ControlTemplate>
                <TextBlock Text="{TemplateBinding Content}"
                           TextWrapping="Wrap"
                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}
                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </ControlTemplate>
        </ContentControl.Template>
    </ContentControl>
    Please write again if you need further assistance.

    Best wishes,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Ove
    Ove avatar
    9 posts
    Member since:
    May 2011

    Posted 24 Oct 2011 Link to this post

    Hi Victor
    I still can not get it to work, I must be doing something wrong, now when I try to show a message I get an exception, se below.
    The example I am using is listed below the message.
    Thanks /Ove

    MissingTemplatePartException
    {"PART_ButtonsPanel - Panel"}

    Message
    PART_ButtonsPanel - Panel

    Stacktrace
       at Telerik.Windows.Controls.MessageBox.RadMessageBoxControl.ac()
       at Telerik.Windows.Controls.MessageBox.RadMessageBoxControl.OnLoaded(Object sender, RoutedEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)



    <ControlTemplate x:Key="InformationMessageTemplate">

            <Border x:Name="border" Padding="12">

                <Grid>

                                <Grid.Background>

                                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                                                                                <GradientStop Color="Black" Offset="0"/>

                                                                                <GradientStop Color="#FF5AE0A6" Offset="1"/>

                                                        </LinearGradientBrush>

                                </Grid.Background>

                    <Grid.RowDefinitions>

                        <RowDefinition Height="Auto"/>

                        <RowDefinition Height="Auto"/>

                        <RowDefinition Height="Auto"/>

                        <RowDefinition Height="*"/>

                    </Grid.RowDefinitions>

                    <StackPanel Orientation="Horizontal">

                        <Image Source="/Images/Warning.png"

                           Margin="12, 12, 0, 24"/>

                        <ContentControl x:Name="PART_Title"

                                HorizontalContentAlignment="Left"

                                FontSize="{StaticResource PhoneFontSizeLarge}"

                                FontFamily="{StaticResource PhoneFontFamilySemiBold}"

                                Margin="{StaticResource PhoneMargin}"/>

                    </StackPanel>

                      

                    <StackPanel Grid.Row="1" Orientation="Horizontal">

                        <ContentControl HorizontalContentAlignment="Left"

                                VerticalContentAlignment="Top"

                                FontSize="{StaticResource PhoneFontSizeNormal}"

                                FontFamily="{StaticResource PhoneFontFamilyNormal}"

                                x:Name="PART_Message"

                                Margin="12, 12, 12, 24">

                            <ContentControl.Template>

                                <ControlTemplate>

                                    <TextBlock Text="{TemplateBinding Content}"

                                       TextWrapping="Wrap"

                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

                                    </ControlTemplate>

                                </ContentControl.Template>

                           

                        </ContentControl>

                    </StackPanel>

                    <CheckBox x:Name="PART_CheckBox"

                          Grid.Row="2"

                          Visibility="Collapsed"

                          HorizontalAlignment="Left"

                          VerticalAlignment="Bottom">

                    </CheckBox>

                    <ContentControl Grid.Row="3"

                                    x:Name="PART_ButtonsContainer"

                                    HorizontalContentAlignment="Stretch">

                                <ContentControl.ContentTemplate>

                                    <DataTemplate>

                                <StackPanel x:Name="PART_ButtonsPanel"

                                                                                                        Orientation="Horizontal">

                                </StackPanel>

                            </DataTemplate>

                                    </ContentControl.ContentTemplate>

                    </ContentControl>

                </Grid>

            </Border>

        </ControlTemplate>

  5. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 Oct 2011 Link to this post

    Hello Ove,

     Thank you for writing.
    I tried using your template and the template validation passed. However in order for the text to wrap, the message part must be in a grid, not a stack panel with orientation Horizontal. This is because when the orientation of the stack panel is horizontal it gives as much horizontal space as the text block requires and no wrapping occurs.
    The grid on the other hand constrains the text block and forces the TextWrapping property to kick in.

    The part of the template that you must change is this:

    <StackPanel Grid.Row="1" Orientation="Horizontal">
                        <ContentControl HorizontalContentAlignment="Left"
                                VerticalContentAlignment="Top"
                                FontSize="{StaticResource PhoneFontSizeNormal}"
                                FontFamily="{StaticResource PhoneFontFamilyNormal}"
                                x:Name="PART_Message"
                                Margin="12, 12, 12, 24">
                            <ContentControl.Template>
                                <ControlTemplate>
                                    <TextBlock Text="{TemplateBinding Content}"
                                       TextWrapping="Wrap"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    </ControlTemplate>
                                </ContentControl.Template>
                            
                        </ContentControl>
                    </StackPanel>

    And you should replace it with this:
    <Grid Grid.Row="1">
                            <ContentControl HorizontalContentAlignment="Left"
                                VerticalContentAlignment="Top"
                                FontSize="{StaticResource PhoneFontSizeNormal}"
                                FontFamily="{StaticResource PhoneFontFamilyNormal}"
                                x:Name="PART_Message"
                                Margin="12, 12, 12, 24">
                                <ContentControl.ContentTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}"
                                       TextWrapping="Wrap"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    </DataTemplate>
                                </ContentControl.ContentTemplate>
     
                            </ContentControl>
                        </Grid>

    I have attached a sample application that demonstrates your template. Best wishes,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Ove
    Ove avatar
    9 posts
    Member since:
    May 2011

    Posted 03 Nov 2011 Link to this post

    Thank You Victor, now it works perfect.
    Best regards
    Ove
  7. Ove
    Ove avatar
    9 posts
    Member since:
    May 2011

    Posted 03 Nov 2011 Link to this post

    Thank You Victor
    Now it works, the text is wrapped.
    Best Regards Ove

Back to Top
DevCraft banner