Google Working with both TextWrapping&TextTrimming at a time in WindowsPhone c#,xaml | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Monday, 2 December 2013

Working with both TextWrapping&TextTrimming at a time in WindowsPhone c#,xaml

Introduction

In windowsphone TextTrimming property has no effect unless the TextWrapping property is set to NoWrap.Both TextWrap and TextTrimming properties works if and only if we set the height & width on our textblock. Yes it is very important to set height&width of textblock while we attempting both properties at a time.


Source File at :  Textwrap&TextTrimming in wp8

Building the Sample

No need to add any other external dll's & libraries.
Note:
1)This sample is targeted on  windows phone 7.1 with wp8 sdk

Description
If you want to know more information about 
1)TextTrimming:
2)TextWrapping

1)Whole xaml

XAML
<phone:PhoneApplicationPage  
    x:Class="Textwrap_and_Trimming.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    shell:SystemTray.IsVisible="True" 
    <!--LayoutRoot is the root grid where all page content is placed--> 
    <Grid x:Name="LayoutRoot" Background="Gray"        <Grid.RowDefinitions            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
 
        <!--TitlePanel contains the name of the application and page title--> 
        <StackPanel x:Name="TitlePanel" Background="Blue" Grid.Row="0" Margin="12,17,0,28"            <TextBlock Text="TextWrapping and TextTrimming" Style="{StaticResource PhoneTextNormalStyle}"/> 
             
        </StackPanel> 
 
        <!--ContentPanel - place additional content here--> 
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,70,0,0"            <Grid.RowDefinitions                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="Auto"/> 
            </Grid.RowDefinitions> 
            <Grid Grid.Row="0"            <TextBlock Foreground="#abcabc" FontSize="18" Text="1.With TextBlock width and height(Working) " Margin="0,-1,0,1"/> 
                <TextBlock Width="434" Margin="10,30,0,0" MaxHeight="60" TextWrapping="Wrap" TextTrimming="WordEllipsis"  
                               LineHeight="18" FontSize="18"                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus commodo dui vulputate laoreet. Donec metus purus, consectetur ut sagittis ut, vestibulum id diam. Suspendisse in urna sem. Ut purus arcu, placerat quis tempus cursus, elementum sed sem. Duis condimentum semper tortor, a pulvinar dolor semper sit amet. 
                </TextBlock> 
            </Grid> 
            <Grid Grid.Row="1"  Margin="0,30,0,0"                <TextBlock Foreground="#abcabc" FontSize="18" Text="2.Without TextBlock width and height(NotWorking) " Margin="0,-1,0,1"/> 
                <TextBlock  TextWrapping="Wrap" TextTrimming="WordEllipsis"  Margin="10,30,0,0"  
                               LineHeight="18" FontSize="18"                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus commodo dui vulputate laoreet. Donec metus purus, consectetur ut sagittis ut, vestibulum id diam. Suspendisse in urna sem. Ut purus arcu, placerat quis tempus cursus, elementum sed sem. Duis condimentum semper tortor, a pulvinar dolor semper sit amet. 
                </TextBlock> 
            </Grid> 
 
        </Grid> 
    </Grid> 
  
</phone:PhoneApplicationPage>
 1)TextWrapping and TextTrimming works at a time with bellow code.Because here i had set the height &width of textblock


XAML
<Grid Grid.Row="0"            <TextBlock Foreground="#abcabc" FontSize="18" Text="1.With TextBlock width and height(Working) " Margin="0,-1,0,1"/> 
                <TextBlock Width="434" Margin="10,30,0,0" MaxHeight="60" TextWrapping="Wrap" TextTrimming="WordEllipsis"  
                               LineHeight="18" FontSize="18"                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus commodo dui vulputate laoreet. Donec metus purus, consectetur ut sagittis ut, vestibulum id diam. Suspendisse in urna sem. Ut purus arcu, placerat quis tempus cursus, elementum sed sem. Duis condimentum semper tortor, a pulvinar dolor semper sit amet. 
                </TextBlock> 
</Grid>
2)TextWrapping and TextTrimming not working at a time with bellow code.Because here i am not set the height &width of textblock
XAML
<Grid Grid.Row="1"  Margin="0,30,0,0"                <TextBlock Foreground="#abcabc" FontSize="18" Text="2.Without TextBlock width and height(NotWorking) " Margin="0,-1,0,1"/> 
                <TextBlock  TextWrapping="Wrap" TextTrimming="WordEllipsis"  Margin="10,30,0,0"  
                               LineHeight="18" FontSize="18"                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus commodo dui vulputate laoreet. Donec metus purus, consectetur ut sagittis ut, vestibulum id diam. Suspendisse in urna sem. Ut purus arcu, placerat quis tempus cursus, elementum sed sem. Duis condimentum semper tortor, a pulvinar dolor semper sit amet. 
                </TextBlock> 
 </Grid>
3)Screenshot

4)In c#,to work with above  both properties at a time,you might be take load event of our textblock and try like this way,
in load event you can get current textblock object like this way,
C#
TextBlock tb = (TextBlock)sender; 
TextBlock tb1=new TextBlock();
 and total c# code in load event like this,
C#
private void LoadTxtdesc(object sender, RoutedEventArgs e) 
        { 
 
            TextBlock tb = (TextBlock)sender; 
            TextBlock tb1=new TextBlock(); 
            tb1.Text = tb.Text; 
            tb1.TextWrapping = TextWrapping.Wrap; 
            tb1.Width = 435; 
            tb1.Height = 75; 
            TextBlock tb2 = new TextBlock(); 
            tb2.Text = tb1.Text; 
            tb2.Height = 75; 
            tb2.TextWrapping = TextWrapping.Wrap; 
            tb2.Width = 435; 
            tb.Text = tb2.Text; 
            tb.TextTrimming = TextTrimming.WordEllipsis; 
            tb.TextWrapping = TextWrapping.Wrap; 
        }

Windows Phone tutorials for beginners key points

This section is included for only windows phone beginners.However this article can covers following questions.Off course these key words is more helpful for getting more best results about this topic in search engines like google/bing/yahoo.. 

1.TextWrapping in windows phone 8 c#,xaml

2.TextTrimming in windows phone 8 c#,xaml

3.Working with both textwrapping and texttrimming in windows phone 8 c#,xaml

4.TextTrimming is not working in windows phone 8 c#,xaml

5.TextTrimming issues in windows phone 8 c#,xaml


Have a nice day by 

No comments:

Post a Comment

Search Engine Submission - AddMe