我使用带有布局网格的LongListSelector创建一个应用程序,我想每行只获得3个项目,但是在WP8中修复了“gridcellsize”属性,所以我想我要将设备屏幕大小设置为1 / 3为每个项目,如下所示:
<phone:LongListSelector ItemTemplate="{...}" LayoutMode="Grid"
GridCellSize="{StaticResource val},{StaticResource val}"/>
我在app.xaml.cs中写过这个,但我不知道如何将它转化为资源
Double val = (Application.Current.RootVisual.RenderSize.Width)/3;
答案 0 :(得分:1)
在您的App.xaml.xs中,您只需
double yourWidth = (Application.Current.RootVisual.RenderSize.Width)/3;
double yourHeight = //whatever you want your height to be
Resources.Add("ScreenWidth", yourWidth);
Resources.Add("ScreenHeight", yourHeight);
然后在你的xaml中你做:
{StaticResource ScreenWidth}
和
{StaticResource ScreenHeight}