- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 silverlight 应用程序中使用 prism 框架,在单独的 XAP 中有多个模块。
我在我的 shell 项目中定义了一个资源字典。在我的模块中,我可以很好地使用资源,但由于模块在运行时加载之前与外壳分离,因此设计器不会显示或识别它们。
有没有办法让模块在设计时知道我的资源,而无需在每个 View xaml 中合并我的资源文件?
我的资源文件在“公共”项目中。
最佳答案
我认为我绝对有设计时资源的解决方案。
好处:
让我们考虑以下解决方案:
您可以在 MyApp.Common 中定义画笔、隐式样式、模板等。
使用我的 SharedResourceDictionary 将 ResourceDictionary 包含在所有项目中。在设计时,它将为每个设计者加载 ResourceDictionary,在运行时,ResourceDictionary 将仅在必要时加载。
使用示例:
在 App.xaml 中包含 SharedResourceDictionary
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<common:SharedResourceDictionary SharedSource="MyApp.Common;component/CommonResources.xaml" />
</ResourceDictionary>
</Application.Resources>
在设计者找不到的地方包含 SharedResourceDictionary 一些共享资源,例如在 MyApp.Module1/UserControl1.xaml
<UserControl.Resources>
<common:SharedResourceDictionary SharedSource="MyApp.Common;component/CommonResources.xaml" />
</UserControl.Resources>
来源:
/// <summary>
/// Loads singleton instance of ResourceDictionary to current scope;
/// </summary>
public class SharedResourceDictionary : ResourceDictionary
{
/// <summary>
/// store weak references to loaded ResourceDictionary, to ensure that ResourceDictionary won't be instanciated multiple times
/// </summary>
protected static Dictionary<string, WeakReference> SharedResources = new Dictionary<string, WeakReference>();
public string SharedSource
{
get { return _SharedSource; }
set
{
if (_SharedSource != value)
{
_SharedSource = value;
sharedSourceChanged();
}
}
}
private string _SharedSource;
private void sharedSourceChanged()
{
//ResourceDictionary will be instanciated only once
ResourceDictionary sharedResourceDictionary;
lock (SharedResources)
{
WeakReference weakResourceDictionary = null;
if (SharedResources.ContainsKey(_SharedSource))
{
weakResourceDictionary = SharedResources[_SharedSource];
}
else
{
SharedResources.Add(_SharedSource, null);
}
if (weakResourceDictionary == null || !weakResourceDictionary.IsAlive) //load ResourceDictionary or get reference to exiting
{
sharedResourceDictionary = (ResourceDictionary)Application.LoadComponent(new Uri(_SharedSource, UriKind.Relative));
weakResourceDictionary = new WeakReference(sharedResourceDictionary);
}
else
{
sharedResourceDictionary = (ResourceDictionary)weakResourceDictionary.Target;
}
SharedResources[_SharedSource] = weakResourceDictionary;
}
if (Application.Current != null)
{
//if sharedResourceDictionary is defined in application scope do not add it to again to current scope
if (containsResourceDictionary(Application.Current.Resources, sharedResourceDictionary))
{
return;
}
}
this.MergedDictionaries.Add(sharedResourceDictionary);
}
private bool containsResourceDictionary(ResourceDictionary scope, ResourceDictionary rs)
{
foreach (var subScope in scope.MergedDictionaries)
{
if (subScope == rs) return true;
if (containsResourceDictionary(subScope, rs)) return true;
}
return false;
}
}
关于c# - 设计时如何在 Prism 模块中使用资源字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7095179/
我想将使用 Prism 4 编写的项目迁移到 Prism 6。 在 Prism 4 中 CompositePresentationEvent类型位于Microsoft.Practices.Compos
Pattern of pub-sub events is that the publisher should not know or care if there are any subscribers
我刚刚使用 MVVMLight、PRISM 和 DryIoc 启动了我的第一个 WPF 应用程序。 App.xaml 引用 prism:PrismApplication,如 https://prism
Microsoft 的 Patterns and Practices 提供的示例非常有用: 大约六个更简单的快速入门 其中涉及具体问题 股票交易者引用实现 ,这是一个相当全面的应用程序 但它缺乏更有用
prism 中共享服务的目的和用途是什么? 哪些事情会让我认为我必须使用共享服务而不是 Event Aggregator? 最佳答案 从事件订阅者的角度来看 EventAggregator,它有利于获
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
寻找一个简单的 helloWorld EventAggregator 示例。我试图理解这一点,并且在遵循 RI 示例时遇到了一些困难。 谢谢 N 最佳答案 Prism 4.0 包括 EventAggr
我只是想知道区域的意义是什么。我想我不明白他们解决的问题。 例如,我看到很多人使用区域作为导航区域,但是为什么不将 ItemsControl 绑定(bind)到 ObservableCollectio
最近想将我的 WPF Prism 应用程序迁移到 7.1,这样做时我遇到了有关 Unity.Abstractions 的丢失引用错误。 将 Prism nuget 软件包升级到 Prism7.1,如下
在我的根 View 模型中,我称之为 await _navigationService.NavigateAsync( "/NavigationPage/Page1of2", useMo
在 2.1.x 时间框架中讨论了与 Prism 的集成,我们是 @2.4.x,Prism 4 现已推出,/contrib 中的 RIStockTrader 示例只是一个默认的 XAML 项目。 它应该
我正在使用 Prism4,并且在我的一个模块中,我试图用一个区域注册一个 View ,并处理它的按钮单击事件(当用户单击 View 上的按钮时发布)。 public class MyModule :
几个月来,我一直在将 Prism 2.0 用于个人项目。我最近听说过 Caliburn,我想知道是否有令人信服的理由让我考虑这样做。 我喜欢 Prism 的动态模块加载能力。我打算为我的应用程序构建模
我正在尝试对我的 Windows 应用商店应用程序中的暂停事件使用react。我添加了适当的回调方法,但遇到了问题: App.Current.Suspending += Current_Suspend
我目前正在尝试完成 this tutorial让 Prism 与 Spring.net 一起工作。 通过 NuGet(或手动引用程序集)引用 Prism4 和 Spring.Net 后,设置 Boot
几个月来,我一直在使用带有以下 XAML 命名空间声明的 Prism 6: xmlns:prism="http://www.codeplex.com/prism" 但我注意到这个命名空间 URL(重定
我在 PRISM 中实现应用程序,它需要从 dll 文件中动态导入模块。我设法做到了 - 他们正在导入,但我无法显示它。我决定创建一个特殊的模块来封装它——让我们称之为 ModuleDock。所以我们
我要创建的是一个 Silverlight 应用程序,其中包含几个选项卡/模块,这些选项卡/模块都是单独的 DLL。 我看到 PRISM 具有似乎针对 UI 的 Shell/Module 概念,并且我找
请帮忙 - 我迷路了! 我正在编写一个具有一些控件和一些屏幕的小型桌面应用程序。这应该稍后与一个小型网站集成,也有一些屏幕。这个想法是让用户编辑视频并选择图像,然后与她的 friend 分享他们的结果
我在使用方法时遇到问题 this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView)); 如果我以某种方法在 Boo
我是一名优秀的程序员,十分优秀!