在我的應用程序中,我有一個列表框,其中包含一個帶有文本塊項目的堆棧面板。文本塊項目具有文字環繞或文本修剪屬性,以避免文本塊項目滑動到可見範圍之外。Windows Phone應用程序 - 如何根據設備寬度使文本環繞
據我所知,文本環繞和文本修剪屬性需要固定寬度來插入換行符。出於這個原因,我設置一個固定的寬度爲標題(寬度=「456」)和描述(寬度=「432」):
<ListBox x:Name="CategoryList" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<StackPanel>
<TextBlock
Style="{StaticResource PhoneTextLargeStyle}"
Text="{Binding Name}"
TextTrimming="WordEllipsis"
Width="456"
/>
<TextBlock
Style="{StaticResource PhoneTextSubtleStyle}"
Margin="12,-6,12,0"
Text="{Binding ContentDescription}"
TextWrapping="Wrap"
Width="432"
/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
現在的問題是,當我打開手機時,水平模式的固定寬度太小。有沒有一種方法可以根據設備寬度來代替固定寬度的寬度?
截圖:
我目前的解決方案是,當一個「方向改變」事件發生時設置一個不同的(也是固定的)寬度。但是還有其他解決方案嗎? –