This is a migrated thread and some comments may be shown as answers.

RadMessagebox with controltemplate, text does not wrap

5 Answers 115 Views
MessageBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ove
Top achievements
Rank 1
Ove asked on 17 Oct 2011, 07:10 PM
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

5 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 19 Oct 2011, 09:56 AM
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 >>

0
Ove
Top achievements
Rank 1
answered on 24 Oct 2011, 04:25 PM
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>

0
Accepted
Victor
Telerik team
answered on 28 Oct 2011, 09:24 AM
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 >>

0
Ove
Top achievements
Rank 1
answered on 03 Nov 2011, 02:08 PM
Thank You Victor, now it works perfect.
Best regards
Ove
0
Ove
Top achievements
Rank 1
answered on 03 Nov 2011, 02:10 PM
Thank You Victor
Now it works, the text is wrapped.
Best Regards Ove

Tags
MessageBox
Asked by
Ove
Top achievements
Rank 1
Answers by
Victor
Telerik team
Ove
Top achievements
Rank 1
Share this question
or