2014-09-19 40 views
0

我创建了一个应用程序使用LongListSelector与布局网格,我想每行只获得3个项目,但“Gridcellsize”属性在WP8中修复,所以我认为我已经来获得设备的屏幕尺寸为每个项目设定1/3,这样的事情:如何获取屏幕大小和作为资源使用 - WP8

<phone:LongListSelector ItemTemplate="{...}" LayoutMode="Grid" 
     GridCellSize="{StaticResource val},{StaticResource val}"/> 

我app.xaml.cs写了这个,但我不知道如何使这个资源

Double val = (Application.Current.RootVisual.RenderSize.Width)/3; 

回答

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} 
相关问题