无法填充数据透视表中的列表视图

时间:2014-12-01 09:21:17

标签: c# xaml windows-phone-8.1

我创建了以下XAML视图:

<Page
    x:Class="Phone.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PhoneMetar"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid x:Name="LayoutRoot">
    <Pivot Title="Pivot Title">
        <PivotItem Header="first option">
                <Grid>
                </Grid>
            </PivotItem>
        <PivotItem Header="second option">
            <Grid>
            </Grid>
        </PivotItem>
        <PivotItem Header="settings">
            <Grid>
                <ListView x:Name="LVSettings" ItemsSource="{Binding SettingsDict}">
                    </ListView>
            </Grid>
        </PivotItem>
    </Pivot>
    </Grid>
</Page>

在后面的代码中,当我试图创建我的LVSettings&#39; listview,我无法访问它。我试图用

填充它
public static Dictionary<string, string> SettingsDict { get; set; }

public static void CreateSettingsList()
{
  SettingsDict = new Dictionary<string, string>();
  SettingsDict.Add("auto download", (Settings.DownloadTimer == true) ? "enabled" : "disabled");
  SettingsDict.Add("download timer", Settings.DownloadInterval.ToString() + " minutes");

            ListView LVSettings = new ListView();
            LVSettings.ItemsSource = SettingsDict;
            LVSettings.SelectionChanged += LVSettings_SelectionChanged;
}

我尝试过一些例子,即使在没有枢轴的情况下创建一个新的XAML页面,我也可以使这个ListView工作,所以这里肯定有一些我无法识别的错误。

你会如此友善地指出我正确的方向吗? 谢谢。

1 个答案:

答案 0 :(得分:0)

我的道歉。我刚解决了这个问题,我不能把我的方法当作静态的。虽然我在这里将这个方法发布为静态,但是当我在一个新页面中测试它时,我并没有说它是静态的,不知道为什么,这就是为什么它起作用。

谢谢。