简体   繁体   English

C#WP8根据文本动态增加控件的大小

[英]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. 我创建了一个控件,如下所示,我最初在文本块中显示受限测试,但是当用户单击readmore按钮时,我必须根据文本块中的文本来扩展控件的大小。 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. 不要给面板(或它的父面板)一个width或height属性,以使其可以增长。 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 在ReadMoreCommand中,您将更改两个文本块的可见性

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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