0
我想要设计我的应用程序,以便根据手机尺寸自定义动态宽度。下面的代码是数据模板我使用列表框我有:动态数据模板宽度
<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
谢谢你在前进,
这可以做到stackpanel,border ...和任何项目我添加到xaml文件? – Ameen
StackPanel和Border都默认为Stretch。只需要为ListBox执行操作。你的DataTemplate的内容是不相关的。 –
我的问题比这更复杂,假设我有一些堆栈项目垂直或horizental。那么我怎样才能使这些组件的高度或宽度相对于他们所在的手机或者堆叠面板的分辨率 – Ameen