C# 名称';foo';命名空间中不存在';http://foo....'
我有一个WPF解决方案,该解决方案由3个项目组成: 1-内部有多个WPF用户控件的项目 2-另一个内部有多个WPF用户控件的项目 3-一个拥有2个以上WPF项目资源的项目 如您所知,如果您有这样的视图的公共设置 -使用相同的FontFamily。 -使用相同的字体大小 -使用相同的重量 -对所有用户控件等使用相同的BackroundBrush。。您需要在所有usercontrol标记中声明此setter,如下所示:C# 名称';foo';命名空间中不存在';http://foo....',c#,wpf,visual-studio-2010,xaml,expression-blend,C#,Wpf,Visual Studio 2010,Xaml,Expression Blend,我有一个WPF解决方案,该解决方案由3个项目组成: 1-内部有多个WPF用户控件的项目 2-另一个内部有多个WPF用户控件的项目 3-一个拥有2个以上WPF项目资源的项目 如您所知,如果您有这样的视图的公共设置 -使用相同的FontFamily。 -使用相同的字体大小 -使用相同的重量 -对所有用户控件等使用相同的BackroundBrush。。您需要在所有usercontrol标记中声明此setter,如下所示: <UserControl .... FontFamily="{Dy
<UserControl ....
FontFamily="{DynamicResource MyFontFamily}"
FontSize="{DynamicResource MyFontSize}"
FontWeight="{DynamicResource MyFontWeight}"
Background="{DynamicResource MyAppBgBrush2}"
Width="250" d:DesignHeight="350">
<Grid/>......
<internalresources:PageBase
xmlns:internalresources="http://schemas.sat.com/winfx/2010/xaml/internalresources">
<Grid>DoWhatEver<Grid/>
<internalresources:PageBase/>
因此,在我的资源项目中,我将AssemlyInfo.cs文件如下:
[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.sat.com/winfx/2010/xaml/internalresources", "Resources")]
此编辑使我能够声明/创建如下用户控件:
<UserControl ....
FontFamily="{DynamicResource MyFontFamily}"
FontSize="{DynamicResource MyFontSize}"
FontWeight="{DynamicResource MyFontWeight}"
Background="{DynamicResource MyAppBgBrush2}"
Width="250" d:DesignHeight="350">
<Grid/>......
<internalresources:PageBase
xmlns:internalresources="http://schemas.sat.com/winfx/2010/xaml/internalresources">
<Grid>DoWhatEver<Grid/>
<internalresources:PageBase/>
道哈特维尔
从现在起,我不必创建一个标记以开头的usercontrol视图
当您向自己的UserControl添加新功能或属性时,继承它是有意义的。在您的情况下,您只需要覆盖设计
您可以通过创建一个资源XAML(BasePageResources.XAML)并在其中使用Setter标记定义您的UI属性来实现这一点
<Style TargetType="Button">
<Setter Property="MinWidth" Value="75"/>
<Setter Property="MinHeight" Value="23"/>
<Setter Property="Margin" Value="11,11,0,0"/>
</Style>
您可以在一个文件中转储所有setter,给setters键,就像CSS类一样。
然后,在App.xaml中,可以包含这些文件,以使其在应用程序范围内可访问
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="BasePageResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
应用程序中的所有按钮现在都应应用您的样式。它比继承要好得多,而且WPF绑定比您的工作更自然。如果你按照它所期望的方式设计,那么混合会给你带来更少的问题。我发现了问题所在。问题在于表达式混合。如果您的项目设置没有任何用于调试| AnyCPU的PropertyGroup,您将遇到此问题。您应该通过文本编辑器将此propertygroup添加到csproj文件中,如下所示:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
x86
真的
满的
假的
bin\Debug\
调试;痕迹
促使
4.
谢谢您的回答。实际上,我在我的资源中使用样式或任何其他自定义的东西,比如datatemplates、itemtemplates。我的意思是,我正在为我的控件执行完全相同的资源机制。我的问题是,当您想在项目中添加WPF用户控件时,它将创建一个cs和xaml文件。有没有什么方法可以像这样将样式应用到您的UserControl