2014-09-19 61 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}