0
我需要將完整的包裝文本轉換爲WPF文本塊。條件是我們不知道文本長度以及窗口大小。如何爲TextBlock設置正確的包裝樣式?
的XAML我已經是:
<Border BorderThickness="1" CornerRadius="6" BorderBrush="#FF405DEF" Padding="5" Margin="5">
<StackPanel Orientation="Horizontal">
<Image HorizontalAlignment="Left" Source="{Binding Path=User.ProfileImageUrl}" Width="48" Height="48"
Name="UserAvatarImage" Stretch="Fill" VerticalAlignment="Top" />
<StackPanel Margin="5,0,0,5" Orientation="Vertical" Grid.Column="1" HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="413">
<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Horizontal" >
<TextBlock Name="UserNameTextBlock" Margin="0,0,10,0" Text="{Binding Path=User.Name}" FontWeight="Bold">UserName</TextBlock>
<TextBlock Foreground="LightGray" >@</TextBlock>
<TextBlock Name="ScreenNameTextBlock" Text="{Binding Path=User.ScreenName}" Foreground="Gray" >ScreenName</TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<TextBlock Margin="0,0,0,0" Foreground="Blue" TextWrapping="Wrap">@ToUserName</TextBlock>
<StackPanel Grid.Column="1">
<TextBlock Margin="5,0,0,0" Text="{Binding Path=Text}" MinHeight="20" MinWidth="200"
VerticalAlignment="Stretch" TextWrapping="WrapWithOverflow">START skf skdjf skdj hfskdjf ksdjhf ksjdhf ksjhf kjsf kjshf kjshkjfhsdf kjsfdkj hskdfj hskdjf hskdjf skjhfksjfks END</TextBlock>
</StackPanel>
</Grid>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
所以,我需要這樣的:
它是通過硬編碼值Width="300"
謝謝瑞秋!你總是幫助我。非常感謝! – 2012-02-20 19:31:41