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

本文关键字:列表 视图 透视 填充 | 更新日期: 2023-09-27 18:32:40

我创建了以下 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"列表视图时,我无法访问它。我正在尝试填充它

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 正常工作,因此这里一定有我无法识别的错误。

你能这么好心地给我指出正确的方向吗?谢谢。

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

我很抱歉。我刚刚解决了这个问题,我不能让我的方法成为静态的。虽然我在这里将该方法发布为静态,但当我在新页面中测试它时,我没有把它放在静态不知道为什么,所以这就是它工作的原因。

谢谢。