如何处理主题的更改?
我有一个 Silverlight 4.0 应用程序,每个主题都有相应的 Styles.xaml。我知道要编写什么代码来更改 ResourceDictionary 等。基本上我需要你的一个概念性想法。我的 URL 中有一个查询字符串,例如 ?uid=3
。主题是基于用户的。所以 A 可以有一个与 B 不同的主题。
据我所知,如果您定义了隐式样式,您可以编写代码来更改应用程序中任何位置的主题,并且效果会很好。但是,如果您的资源字典定义了显式样式,那么您必须在 App.xaml.cs 构造函数中强制设置主题。如果我错了请告诉我!现在的问题是用户可能会浏览 A 的个人资料,然后可能会转到 B 的个人资料。如果发生这种情况,主题将不会更改,因为 App.xaml.cs 的构造函数仅在应用程序启动时运行一次。我该如何处理这个问题?一种选择是永远不创建显式样式并保持所有样式隐式。你们还有其他选择吗?
第二个问题是,随着用户浏览页面,主题不断变化,我是否需要继续进行 Web 服务调用来检索适用于该特定用户的主题?当您在每个页面中进行额外的 Web 服务调用时,这将对性能造成巨大影响。这是可以接受的还是您有其他更好的选择?
PS:另一种解决方案是我创建一个基本页面并在该页面中存储一个 _previousUserId。如果 currentUserId(从查询字符串中获取)与 _previousUserId 不匹配,我会调用以查看该特定用户为其个人资料设置的主题,并在 Webservice 调用之后,使 _previousUserId = currentUserId
(因此只要用户在该用户 ID 的个人资料中,下次就不会进行呼叫)。
但解决方案的另一个问题是:只要 Web 服务没有响应获取新主题,页面就会加载旧主题的所有数据。这看起来有问题。例如。用户首先访问 A 的个人资料,因此将从 Web 服务获取并应用他的主题。然后他访问 B 的个人资料,但主题仍将是 A 的,直到获取 B 主题的异步调用返回。
你如何处理所有这些事情?
I have a Silverlight 4.0 application and it's corresponding Styles.xaml for each of the theme. I know what code to write to change the ResourceDictionary and all. Basically I need a conceptual idea from you. I have a query string in my URL like ?uid=3
. The themes are users based. So A can have a theme different than B.
As far as I know, if you have implicit styles defined, you can write the code to change the theme anywhere in your application and it will work out just fine. However, if your resource dictionary defines explicit styles then you have to compulsorily set the theme in App.xaml.cs constructor. Let me know if I am wrong! Now the problem with this is the user may browse A's profile and then may shift to B's. If this happens the theme won't be changed because App.xaml.cs's constructor runs only once when your application starts. How do I handle this? One option is to never create explicit styles and keep all of them implicit. Do you guys have any other option?
Second question is as the theme keeps changing as user browses the page, do I need to keep making a webservice call to retrieve what theme applies to this specific user? This will make a huge performance hit as you make an extra webservice call in every page. Is this acceptable or do you have any other better option?
P.S: One other solution is I create a base page and in that page store a _previousUserId. If the currentUserId (fetched from query string) doesn't match the _previousUserId, I make a call to see which theme this specific user has set for his profile and after webservice call, make _previousUserId = currentUserId
(so next time call won't be made as long as the user is on this userId's profile).
But yet another problem with solution is: the page will load all it's data with old theme as long as the response from the webservice to get the new theme doesn't come. This looks buggy. Eg. The user first visits A's profile so his theme will be fetched from webservice and applied. Then he visits B's profile but the theme will be still A's until the asynchronous call to get B's theme returns.
How do you handle all of these things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论