在我的应用程序中实现书签/收藏夹类型功能

发布于 2024-10-21 22:00:13 字数 235 浏览 1 评论 0原文

我正在研究如何在我的应用程序中实现书签或收藏夹类型函数的概念。基本上,这使用户能够从我的应用程序保存最喜欢的页面,然后将其显示在收藏夹列表中。当然,最喜欢的也需要删除。 我可能只需要应用程序中的两到三条信息,例如“页面名称”和“页面地址”。

我当前的想法是使用独立存储并创建 XML 文件,但这被证明是困难的。

编辑:我不是要求代码或任何东西,而是更多关于如何处理这个问题以及使用哪些方法的想法。

非常感谢。

I am looking into concepts of how to implement a bookmarks or favouities type function into my application. Basically, this enables the users to save favourite pages from my app, which are then displayed on a list of favourites. The favouties of course need to be deleted as well.
I would proably just need two or three pieces of information like 'page name' and 'address of page' within my application.

My currrent trail of thought is with isolated storage and creating an XML file but this is proving difficult.

EDIT,: I am not asking for code or anything, but more after ideas on how to approach this and which methods to use.

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

临走之时 2024-10-28 22:00:14

这将取决于用户实际喜欢的内容,但这里是我如何处理此问题的快速一般概述。 (这很像我在实际项目中做类似事情的方式。)

如果您有页面的字典/列表(或类似的集合/枚举),我只需一个单独的集合,其中存储最喜欢的索引页。

为了保留收藏夹,我只需序列化该集合(为了速度,我会使用 json 而不是 xml)并将其保存到isolatedStorage 中的文件中。

添加到收藏夹和从收藏夹中删除只是更新集合的一种情况。

为了显示收藏夹,我将创建一个包含键/索引列表的类,并查找完整的页面列表以查看它们的名称是什么以及如果选择则导航到哪里。

This will depend on what the user is actually favouriting but here's a quick generic overview of how I'd approach this. (THis is quite like how I've done similar things in real projects.)

If you had a dictionary/list (or similar collection/enumerable) of your pages, I'd just have a separate collection which stored the indexes of the favourited pages.

To persist the favourites I'd just serialize the collection (I'd use json rather than xml for speed) and save it to a file in IsolatedStorage.

Adding to and deleteing from the favourites woudl just be a case of updating the collection.

To display the favourites I'd create a class which wraps the list of keys/indexes and does a look up on the full list of pages to see what their names are and where to navigate to if selected.

御弟哥哥 2024-10-28 22:00:14

您可以在独立存储之上使用一些数据库之王,例如 Sterling DB。然后您可以使用 LINQ 查询/删除收藏夹。

希望这有帮助

you can use some king of database on top of isolated storage, like Sterling DB for example. Then you can query / delete favorites using LINQ.

Hope this helps

韵柒 2024-10-28 22:00:13

我 100% 同意马特的观点。

Overflow7 中,我使用实际的 XAML 导航 URL每个书签 - 然后使用单个 JSON 文件(使用 JSON.Net)将书签列表保留在单个书签中

因此,例如,搜索的书签实际上存储在一个大对象中,例如:

"windows-phone-7" : {
   "Bookmark" : "/Views/SearchPage.xaml?Site=StackOverflow&Tag=windows-phone-7"
},
"Stuart" : {
   "Bookmark" : "/Views/UserPage.xaml?Site=StackOverflow&User=12341"
},

这使得书签导航机制确实很简单 - 但这确实意味着我以后很难更改我的页面名称。为了将来的校对,最好将页面名称从持久书签中分离出来。

为了实际制作/清除书签,我在应用程序栏上使用一个图标 - 但唯一的问题是你不能使用颜色来显示打开的书签。 /off 状态 - 由于 ApplicationBar 在浅色主题模式下的工作方式,您必须使用一些不同的图标形状来显示书签是否打开/关闭。

书签的加载和保存使用:

    private const string BookmarkFileName = "Bookmarks.json";

    private void LoadBookmarks()
    {
        BookmarkViewModel = new AppBookmarkViewModel();
        try
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (false == store.FileExists(BookmarkFileName))
                {
                    return;
                }

                using (var fs = store.OpenFile(BookmarkFileName, System.IO.FileMode.Open))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        var text = sr.ReadToEnd();
                        BookmarkViewModel = JsonConvert.DeserializeObject<AppBookmarkViewModel>(text);
                    }
                }
            }
        }
        catch (Exception exc)
        {
            BookmarkViewModel = new AppBookmarkViewModel();
            MessageBox.Show("Sorry - there was a problem reading bookmarks - " + exc.Message);
        }
    }

    public void SaveBookmarks()
    {
        try
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(BookmarkFileName))
                {
                    store.DeleteFile(BookmarkFileName);
                }

                using (var fs = store.OpenFile(BookmarkFileName, System.IO.FileMode.CreateNew))
                {
                    using (var sw = new StreamWriter(fs))
                    {
                        var text = JsonConvert.SerializeObject(BookmarkViewModel);
                        sw.Write(text);
                    }
                }
            }
        }
        catch (Exception exc)
        {
            // don't show message box during shutdown
            //MessageBox.Show("Sorry - there was a problem reading bookmarks - " + exc.Message);
        }
    }

I agree 100% with Matt.

In Overflow7 I use the actual XAML Navigation URL for each of the bookmarks - and then persist the list of bookmarks in a single using a single JSON file (using JSON.Net)

So, for example, a bookmark to a search is actually stored in a big object like:

"windows-phone-7" : {
   "Bookmark" : "/Views/SearchPage.xaml?Site=StackOverflow&Tag=windows-phone-7"
},
"Stuart" : {
   "Bookmark" : "/Views/UserPage.xaml?Site=StackOverflow&User=12341"
},

This makes the bookmark navigation mechanism really easy - but does mean that it would be hard for me to later change my page names. For future proofing, it might be better to split the page name out from the persisted bookmark

For actually making/clearing bookmarks I use an icon on the ApplicationBar - the only problem with this though is that you can't use colour to show the on/off state - because of the way the ApplicationBar works in light theme mode you have to use some distinct icon shape to show whether the bookmark is on/off.

Load and save of bookmarks is using:

    private const string BookmarkFileName = "Bookmarks.json";

    private void LoadBookmarks()
    {
        BookmarkViewModel = new AppBookmarkViewModel();
        try
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (false == store.FileExists(BookmarkFileName))
                {
                    return;
                }

                using (var fs = store.OpenFile(BookmarkFileName, System.IO.FileMode.Open))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        var text = sr.ReadToEnd();
                        BookmarkViewModel = JsonConvert.DeserializeObject<AppBookmarkViewModel>(text);
                    }
                }
            }
        }
        catch (Exception exc)
        {
            BookmarkViewModel = new AppBookmarkViewModel();
            MessageBox.Show("Sorry - there was a problem reading bookmarks - " + exc.Message);
        }
    }

    public void SaveBookmarks()
    {
        try
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(BookmarkFileName))
                {
                    store.DeleteFile(BookmarkFileName);
                }

                using (var fs = store.OpenFile(BookmarkFileName, System.IO.FileMode.CreateNew))
                {
                    using (var sw = new StreamWriter(fs))
                    {
                        var text = JsonConvert.SerializeObject(BookmarkViewModel);
                        sw.Write(text);
                    }
                }
            }
        }
        catch (Exception exc)
        {
            // don't show message box during shutdown
            //MessageBox.Show("Sorry - there was a problem reading bookmarks - " + exc.Message);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文