【问题标题】:How to get screen size and use as resources - WP8如何获取屏幕尺寸并用作资源 - WP8
【发布时间】:2014-09-19 08:58:34
【问题描述】:

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

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

我在 app.xaml.cs 中写了这个,但我不知道如何将它变成资源

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

【问题讨论】:

    标签: c# xaml windows-phone-8 longlistselector


    【解决方案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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多