C#/XAML Assigning Picker list ItemsSource property from a Linq Query containing strings Error: CS0029

C#/XAML Assigning Picker list ItemsSource property from a Linq Query containing strings Error: CS0029

我正在尝试使用对本地 SQLite 数据库的 Linq 查询来分配 Picker ItemsSource 属性。但是,我得到 "{ Page_Title = Test 1 }" 而不是 Test 1。 其中:

Page_Title是SQLite中的列名Table

测试1是我想要的值return

我假设我得到的原因是因为我使用的是列表而不是字符串。但是,当我尝试使用列表时出现以下错误:

CS0029:无法将类型“System.Collections.Generic.List 匿名类型:字符串 Page_Title”隐式转换为“System.Collections.Generic.List 字符串”

我尝试了 .ConvertAll 来转换字符串,它确实删除了 {Page_Title = } 到 return 只是测试 1,但是它被 return 编辑为每个字符作为列表中的一个项目。如下图:

“T”

“e”

"s"

“t”

“1”

使用对象编码

        VM_AnalyzePage CurrentPage = new VM_AnalyzePage();
                var pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
                            where UserPageTbl.User_ID == App.user
                            select new
                            {
                                UserPageTbl.Page_Title

                            }).Distinct().OrderBy(Page_Title => Page_Title).ToList<object>();


            CurrentPage.PageList = pageList;

带字符串的代码

            var pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
                            where UserPageTbl.User_ID == App.user
                            select new
                            {
                                UserPageTbl.Page_Title

                            }).Distinct().OrderBy(Page_Title => Page_Title).ToList();


            CurrentPage.PageList = pageList;

这是我要为其设置值的 class。请注意,当我尝试转换为字符串时,我在下面将“object”更改为“string”:

public class VM_AnalyzePage : INotifyPropertyChanged

{

    //properties
    private List<object> pageList;


    public List<object> PageList
    {
        get
        {
            return pageList;
        }
           
        set
        {
            pageList = value;
        }
    }

我也试过将“pageList”变量强制转换为下面的 List 字符串,但我得到了同样的错误:

            List<string> pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
                            where UserPageTbl.User_ID == App.user
                            select new
                            {
                                UserPageTbl.Page_Title

                            }).Distinct().OrderBy(Page_Title => Page_Title).ToList();


            CurrentPage.PageList = pageList;

我能够通过用真正的 LINQ 语句替换 SQL 语句来克服:

                List<string> pageList = conn.Table<UserPageTbl>().Where(t => t.User_ID == App.user).Select(t=>t.Page_Title).Distinct().ToList();