Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获得屏幕大小并用作资源-WP8_C#_Xaml_Windows Phone 8_Longlistselector - Fatal编程技术网

C# 如何获得屏幕大小并用作资源-WP8

C# 如何获得屏幕大小并用作资源-WP8,c#,xaml,windows-phone-8,longlistselector,C#,Xaml,Windows Phone 8,Longlistselector,我正在使用带有布局网格的LongListSelector创建一个应用程序,我希望每行仅获取3个项目,但WP8中的“gridcellsize”属性是固定的,因此我认为我必须为每个项目将设备屏幕大小设置为1/3,如下所示: <phone:LongListSelector ItemTemplate="{...}" LayoutMode="Grid" GridCellSize="{StaticResource val},{StaticResource val}"/> 在A

我正在使用带有布局网格的LongListSelector创建一个应用程序,我希望每行仅获取3个项目,但WP8中的“gridcellsize”属性是固定的,因此我认为我必须为每个项目将设备屏幕大小设置为1/3,如下所示:

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

在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 ScreenWidth}
{StaticResource ScreenHeight}