我想将我的应用程序设计为具有根据手机尺寸定制的动态宽度。下面的代码是我用于列表框的数据模板:
<DataTemplate x:Key="FlightsTemplate">
<StackPanel Orientation="Horizontal" Margin="3" Background="#FF171717" Height="35">
<TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="60" Text="{Binding text1}"/>
<TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="80" Text="{Binding text2}"/>
<TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="150" Text="{Binding text3}"/>
<TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="90" Text="{Binding text4}"/>
<TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="70" Text="{Binding text5}"/>
</StackPanel>
</DataTemplate>
如何将width属性设置为相对于我知道可以使用以下代码行检索的手机分辨率:
System.Windows.Application.Current.Host.Content.ActualWidth
提前谢谢你,
答案 0 :(得分:0)
您需要为ListBox的HorizontalContentAlignment
ItemContainerStyle
像这样:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>