【发布时间】:2013-12-19 08:17:00
【问题描述】:
我有一个 WPF 解决方案,这个解决方案包含 3 个项目: 1-一个内部有多个 WPF 用户控件的项目 2-另一个项目里面有几个 WPF 用户控件 3-A 项目,其中包含上述 2 个 WPF 项目的资源。
如您所知,如果您有这样的视图的通用设置 - 使用相同的字体系列。 - 使用相同的字体大小 - 使用相同的字体粗细 - 对所有用户控件等使用相同的 BackroundBrush。您需要在所有用户控件标签中声明此设置器,如下所示:
<UserControl ....
FontFamily="{DynamicResource MyFontFamily}"
FontSize="{DynamicResource MyFontSize}"
FontWeight="{DynamicResource MyFontWeight}"
Background="{DynamicResource MyAppBgBrush2}"
Width="250" d:DesignHeight="350">
<Grid/>......
但我不想在我的所有用户控件中编写相同的设置器。出于这个原因,我决定将此属性设置移动到一个新的 c# 文件中并在资源项目中找到它。
using System.Windows.Controls;
namespace Resources
{
public class PageBase : UserControl
{
public PageBase()
{
SetResourceReference(FontFamilyProperty, "MyFontFamily");
SetResourceReference(FontSizeProperty, "MyFontSize");
SetResourceReference(FontWeightProperty, "MyFontWeight");
SetResourceReference(BackgroundProperty, "MyAppBgBrush2");
}
}
}
所以,在我的资源项目中,我像这样编辑了 AssemlyInfo.cs 文件:
[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.sat.com/winfx/2010/xaml/internalresources", "Resources")]
此编辑使我能够声明/创建如下用户控件:
<internalresources:PageBase
xmlns:internalresources="http://schemas.sat.com/winfx/2010/xaml/internalresources">
<Grid>DoWhatEver<Grid/>
<internalresources:PageBase/>
从现在开始,我不必创建标签开头的用户控件视图
<UserControl....,我可以从<internalresources:PageBase开始......
我的问题是,VisualStudio 2010 可以向我展示我的所有用户控件的设计但 Expression blend 不能。有趣的是,在 VS 和 Blend 中,我的项目编译没有任何错误但是当我尝试在 blend 中打开我的视图时,它说:
-命名空间“PageBase”在命名空间“http://schemas.sat.com/winfx/2010/xaml/internalresources”中不存在
P.S:引用已正确添加到我的项目中,并且我的项目适合使用 blend 打开。
【问题讨论】:
标签: c# wpf visual-studio-2010 xaml expression-blend