动态堆栈面板样式 wp7
我创建了一个列表框,其中每个项目都有 4 张图片。它运行速度很快,而且非常甜蜜和花花公子,但我不知道如何根据屏幕分辨率动态地做到这一点。
所以目前我有连续 4 张图片 90x90 + 5 边距,但是如果屏幕分辨率不够大,无法支持 4 张图片,只支持 3 张怎么办?例如,如果我倾斜手机,并且我变红,他们也会引入 320×480 分辨率。
<ListBox Height="646" HorizontalAlignment="Left" Margin="6,19,0,0" Name="MainListbox" VerticalAlignment="Top" Width="444" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
private void GetDataToBind(List<string> images, int spliter)
{
for (int i = spliter; i < images.Count; i += spliter)
{
StackPanel temp = new StackPanel();
temp.Orientation = System.Windows.Controls.Orientation.Horizontal;
for (int j = i - spliter; j < i && j < images.Count + spliter; j++)
{
Grid tempGrid = new Grid();
Rectangle temprect = new Rectangle();
temprect.Fill = new SolidColorBrush(Colors.White);
temprect.Height = 90;
temprect.Width = 90;
tempGrid.Children.Add(temprect);
tempGrid.Children.Add(GetImageSourceFromString(images[j]));
temp.Children.Add(tempGrid);
}
MainListbox.Items.Add(temp);
}
}
int splitter 确定连续有多少张图片。
解决方案我对包裹面板、LazyListbox 不感兴趣。有人知道用动态风格或优雅的方式解决这个问题的方法吗?
此致
I've created a listbox with 4 pictures for every item. It is working fast and its all sweet and dandy, but I don't know how to do this dinamicaly depending from screen resolution.
So currently I have 4 pictures in a row 90x90 + 5 margin, but what if the screen resolution isn't big enough to support 4 pictures only 3? For example if I tilt the phone, and I've red they are going to introduce 320×480 resolution as well.
<ListBox Height="646" HorizontalAlignment="Left" Margin="6,19,0,0" Name="MainListbox" VerticalAlignment="Top" Width="444" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
private void GetDataToBind(List<string> images, int spliter)
{
for (int i = spliter; i < images.Count; i += spliter)
{
StackPanel temp = new StackPanel();
temp.Orientation = System.Windows.Controls.Orientation.Horizontal;
for (int j = i - spliter; j < i && j < images.Count + spliter; j++)
{
Grid tempGrid = new Grid();
Rectangle temprect = new Rectangle();
temprect.Fill = new SolidColorBrush(Colors.White);
temprect.Height = 90;
temprect.Width = 90;
tempGrid.Children.Add(temprect);
tempGrid.Children.Add(GetImageSourceFromString(images[j]));
temp.Children.Add(tempGrid);
}
MainListbox.Items.Add(temp);
}
}
int splitter determinates how many pictures are in a row.
Solutions I'm not interested wrap panel, LazyListbox. Does someone know a way to solve this with Dynamic style or something elegant?
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Ku6opr 所说,所有设备的特定屏幕分辨率均为 480x800。随着未来低成本设备的推出,这种情况将会改变,但它们也将具有严格定义的分辨率 (320x480)。
实际上,您将拥有两种可以使用的屏幕格式。然后询问设备的分辨率和相应的样式将是一件简单的事情。不过,它不需要是动态的 - 您可以设置 2 种样式(每个分辨率一种),然后根据报告的分辨率应用样式。
As Ku6opr says, all devices have a specific screen resolution of 480x800. This is set to change with the introduction of lower cost devices in the future, but they will also have a rigidly defined resolution (320x480).
In effect what you will have is 2 screen formats to work with. It would then be a simple matter to interrogate the device for the resolution, and style accordingly. It doesn't need to be dynamic, though - you can set up 2 styles (one per resolution) and then apply the styling according to the resolution reported.
所有 WP7 设备都具有相同的屏幕分辨率 480x800。您不必担心某些图像不适合屏幕。
All WP7 devices have the same screen resolution 480x800. You don't need to afraid that some images don't fit to screen.