C# WPF文本块高度

C# WPF文本块高度,c#,wpf,windows-8,windows-store-apps,textblock,C#,Wpf,Windows 8,Windows Store Apps,Textblock,我正在动态添加文本块,但高度有问题 有时文本看起来是剪切的。此外,应用程序似乎为所有元素指定了相同的高度 xaml: <ScrollViewer Grid.Column="2" x:Name="DetailInfoScroll" Margin="25,0,50,0" Style="{StaticResource HorizontalScrollViewerStyle}"> <VariableSizedWrapG

我正在动态添加文本块,但高度有问题

有时文本看起来是剪切的。此外,应用程序似乎为所有元素指定了相同的高度

xaml:

<ScrollViewer Grid.Column="2" x:Name="DetailInfoScroll"  
              Margin="25,0,50,0"
              Style="{StaticResource HorizontalScrollViewerStyle}">
    <VariableSizedWrapGrid Grid.Column="2" Margin="25,0,50,35" 
                           HorizontalAlignment="Left"  
                           VerticalAlignment="Center" 
                           x:Name="StkText">                      
    </VariableSizedWrapGrid>
</ScrollViewer>
演示:

不确定这是否是完美的解决方案,但我找到了一种方法,使height属性不会锁定到该行的列。问题是,它会一直沿着第一列向下,然后再将任何内容放入第二列。如果WrapPanel不锁定同一行中的所有高度,就无法轻松地水平添加元素

这还可以通过使用样式来消除代码落后

下面是一个正在使用的示例

<Window.Resources>
    <Style TargetType="TextBlock">
        <Setter Property="Width" Value="400"/>            
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="TextWrapping" Value="Wrap"/>  
        <Setter Property="Margin" Value="10"></Setter>
    </Style>
</Window.Resources>
<WrapPanel Orientation="Vertical" Width="850" Background="Black" Height="300" >
    <TextBlock Text="Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do."/>
    <TextBlock Text="Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers."/>
    <TextBlock Text="Questions that need improvement may be closed until someone fixes them."/>
    <TextBlock Text="All questions are tagged with their subject areas. Each can have up to 5 tags, since a question might be related to several subjects. Click any tag to see a list of questions with that tag, or go to the tag list to browse for topics that interest you."/>
    <TextBlock Text="Your reputation score goes up when others vote up your questions, answers and edits."/>        
</WrapPanel>


不确定这是否是完美的解决方案,但我找到了一种方法,使height属性不会锁定到该行的列。问题是,它会一直沿着第一列向下,然后再将任何内容放入第二列。如果WrapPanel不锁定同一行中的所有高度,就无法轻松地水平添加元素

这还可以通过使用样式来消除代码落后

下面是一个正在使用的示例

<Window.Resources>
    <Style TargetType="TextBlock">
        <Setter Property="Width" Value="400"/>            
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="TextWrapping" Value="Wrap"/>  
        <Setter Property="Margin" Value="10"></Setter>
    </Style>
</Window.Resources>
<WrapPanel Orientation="Vertical" Width="850" Background="Black" Height="300" >
    <TextBlock Text="Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do."/>
    <TextBlock Text="Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers."/>
    <TextBlock Text="Questions that need improvement may be closed until someone fixes them."/>
    <TextBlock Text="All questions are tagged with their subject areas. Each can have up to 5 tags, since a question might be related to several subjects. Click any tag to see a list of questions with that tag, or go to the tag list to browse for topics that interest you."/>
    <TextBlock Text="Your reputation score goes up when others vote up your questions, answers and edits."/>        
</WrapPanel>


为什么不在xaml中使用样式,而不是在代码中重复生成?空的红色框应该是什么意思?为什么不在xaml中使用样式,而不是在代码中重复生成?那些红色的空盒子是什么意思?