简体   繁体   中英

C# WP8 dynamically increase control size according to text

I am trying to achieve below. I have created a control as you can see below where I am showing restricted test in textblock initially but as user click on readmore button I have to expand control size according to text inside the text block. Refer below image.

在此处输入图片说明

How to achieve this any help? This control will be added in another user control which is collection of this control.

If you are restricting the text by some means and then adding more text, you can accomplish this with really any panel control. Do not give the panel (or it's parent) a width or height property so that it can grow. Here is an example using a Grid

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <TextBlock Text="Event"/>
    <TextBlock Text="{Binding EventSummary}" Grid.Row="1" Visibility="{Binding SummaryVis}"/>
    <TextBlock Text="{Binding EventDescription}" Grid.Row="1" Visibility="{Binding DescriptionVis}" />
    <HyperlinkButton HorizontalAlignment="Right" Content="read more" Command="{Binding ReadMoreCommand}" />
    <!-- Buttons -->
    <StackPanel Orientation="Horizontal" />
</Grid>

In the ReadMoreCommand you would change the visibility of the two textblocks

private void ReadMore(object val)
{
    DescriptionVis = Visibility.Visible;
    SummaryVis = Visibility.Collapsed;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM