如何从XAML中的CLR命名空间映射类型而不是声明它的汇编?(How do I map a type from a CLR namespace in XAML from an assembly other than the one where it's declared?)
在XAML中,我想使用来自两个不同程序集的类型,每个程序集都有自己的命名空间。 我不想在
xmlns:<xml-namespace>="<clr-namespace>"
属性中显式声明名称空间,而是使用[XmlnsDefinition]
程序集属性将URI映射到这些类型的名称空间。其中一个程序集本身与WPF无关,所以我想避免它引用与WPF相关的程序集,特别是
System.Xaml.dll
程序集,如果该程序集使用[XmlnsDefinition]
属性。我有一个像这样组织的Visual Studio解决方案:
Gu.Units.sln Gu.Units.csproj // no ref to System.Xaml here Gu.Units.Wpf.csproj // references Gu.Units and System.Xaml在
Gu.Units.Wpf.csproj
我有这个映射:[assembly: XmlnsDefinition("http://Gu.com/Units", clrNamespace: "Gu.Units", AssemblyName = "Gu.Units")] [assembly: XmlnsDefinition("http://Gu.com/Units", clrNamespace: "Gu.Units.Wpf", AssemblyName = "Gu.Units.Wpf")] [assembly: XmlnsPrefix("http://Gu.com/Units", "units")]
我试图在XAML中使用它,如下所示:
<UserControl x:Class="Gu.Units.Wpf.Demo.Sample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:units="http://Gu.com/Units"> <Label Content="{x:Static units:LengthUnit.Millimetres}" /> </UserControl>
但由于某种原因,名称空间
Gu.Units
似乎被忽略了。 也就是说,它不包含在URIhttp://Gu.com/Units
标识的XML命名空间中。 相反,我得到:名称“LengthUnit”在命名空间“ http://Gu.com/Units ”中不存在。
XAML中的显式名称空间声明 - 即具有
xmlns:units="clr-namespace:Gu.Units;assembly=Gu.Units"
- 工作正常,但我也想避免这种情况。有没有办法,我可以让我的
Gu.Units.Wpf.dll
程序集提供必要的[XmlnsDefinition]
属性来映射Gu.Units.Wpf.dll
程序[XmlnsDefinition]
的命名空间,以便后者本身不需要对System.Xaml.dll
的引用System.Xaml.dll
,System.Xaml.dll
没有任何特定于XAML的代码?In XAML, I would like to use types from two different assemblies, each with their own namespace. Rather than declaring the namespaces explicitly in an
xmlns:<xml-namespace>="<clr-namespace>"
attribute, I would like to use the[XmlnsDefinition]
assembly attribute to map a URI to the namespaces for those types.One of the assemblies is not relevant to WPF per se, so I would like to avoid it having any reference to WPF-related assemblies, and in particular the
System.Xaml.dll
assembly which would be required if that assembly used the[XmlnsDefinition]
attribute.I have a Visual Studio Solution that is organized like this:
Gu.Units.sln Gu.Units.csproj // no ref to System.Xaml here Gu.Units.Wpf.csproj // references Gu.Units and System.XamlIn
Gu.Units.Wpf.csproj
I have this mapping:[assembly: XmlnsDefinition("http://Gu.com/Units", clrNamespace: "Gu.Units", AssemblyName = "Gu.Units")] [assembly: XmlnsDefinition("http://Gu.com/Units", clrNamespace: "Gu.Units.Wpf", AssemblyName = "Gu.Units.Wpf")] [assembly: XmlnsPrefix("http://Gu.com/Units", "units")]
I have tried to use it in XAML like this:
<UserControl x:Class="Gu.Units.Wpf.Demo.Sample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:units="http://Gu.com/Units"> <Label Content="{x:Static units:LengthUnit.Millimetres}" /> </UserControl>
But for some reason, the namespace
Gu.Units
seems to be ignored. That is, it is not included in the XML namespace identified by the URIhttp://Gu.com/Units
. Instead, I get:The name "LengthUnit" does not exist in the namespace "http://Gu.com/Units".
An explicit namespace declaration in the XAML — i.e. having
xmlns:units="clr-namespace:Gu.Units;assembly=Gu.Units"
— works fine but I would also like to avoid that.Is there a way that I can have my
Gu.Units.Wpf.dll
assembly provide the necessary[XmlnsDefinition]
attribute to map the namespace from theGu.Units.dll
assembly, so that the latter does not itself need a reference toSystem.Xaml.dll
, nor have any XAML-specific code in it at all?
原文:https://stackoverflow.com/questions/33862121
最满意答案
如果我理解你正确,使用你的语法,你想要掌握你的PhoneListController对象,这样你就可以定义它的解析属性,对吧?
你可以这样做:
var phoneListCtrl = mod.controller('PhoneListController', ["$scope", function($scope) { foo bar … }]); phoneListCtrl.resolve = { //code here }
If I understood you right, using your syntax, you want to get hold of your PhoneListController object so you can define It's resolve property, right?
You can do this:
var phoneListCtrl = mod.controller('PhoneListController', ["$scope", function($scope) { foo bar … }]); phoneListCtrl.resolve = { //code here }
相关问答
更多-
您可以在角度服务中创建一个object ,该object将具有各种可共享属性。 您可以直接使用控制器范围变量分配该变量。 因此,两个控制器的变量使用引用是相同的,就像我们给myCtrl1和myCtrl2只有一个副本的范围变量。 因此,一个变量的更改会更新另一个变量。 标记1st Controller
角度普遍的决心(Angular universal resolve)[2021-11-01]
是的, when补丁应该按预期工作when显示。 它应该是 return numbersService.getAvailableCodes().$promise.then(function(data) { ... 使用此承诺作为路线解决方案。 Yes, the shown when patch should work as expected. And it should be return numbersService.getAvailableCodes().$promise.th ...将缓存厂添加到控制器(Add Cache Factory to Controller)[2021-09-22]
而不是CacheFactory使用$cacheFactory 。 文档在这里 Instead of CacheFactory use $cacheFactory. Documentation hereangular1:如何等待父控制器中的promise解析?(angular1: How to wait for promise to resolve in parent controller?)[2022-03-22]
好吧,将API调用函数包含在下面 Api.Account.get(token: $scope.current_user.account_id).$promise.then ((response) -> accountFactory.set(response) $scope.account = accountFactory.account ) 并在accountPaymentMethodsCtrl调用此函数并等待承诺解决,就像你在accountCtrl所做的那样。 这将工作:) 干杯! We ...根据您分享的内容,控制器应该在管理模块上创建,例如 var adminModule=angular.module('admin'); // This syntax get the module adminModule.controller('AdminContentController', ['$scope', 'entityService', 'gridService', 'gridSelectService', 'localStorageService', function ($sc ...尝试这个... $http.post('/droplets/', {drop: drop, userId: $scope.user.id}) 编辑 回答你关于无法在工厂中访问范围的评论...... 在调用工厂代码之前更改控制器中的数据。 $scope.createNewDroplet = function () { $scope.drop.user_id = $scope.user.id; drop.create($scope.drop).success(function(droplet) { ...controller不应该返回任何东西。 它应该提供操作并仅执行一些初始化和销毁操作。 例如 controller: function ($stateParams, $scope, someService){ // naive sync init this.items = someService.load($sateParams.id); // example of action this.edit = function(item) { ... ...调用控制器和将$resolve属性放在范围之间显然存在延迟。 angular.module("myApp").controller("test", function($scope, $timeout) { var vm = $scope; console.log("test controller") //console.log(vm); console.log("$resolve=",$scope.$resolve); //Undefined $timeout(fu ...我认为您的问题出在您的控制器中。 缺少热键依赖 angular.module('mainApp', ['ui.mask', "ngRoute", "cfp.hotkeys"]) .controller('ndcController', ["$scope", "$location", "$timeout", "fieldService", "entityService", "$filter", "authorizedUserService", "$q", "gerimedService","hotke ...如果我理解你正确,使用你的语法,你想要掌握你的PhoneListController对象,这样你就可以定义它的解析属性,对吧? 你可以这样做: var phoneListCtrl = mod.controller('PhoneListController', ["$scope", function($scope) { foo bar … }]); phoneListCtrl.resolve = { //code here } If I understood you r ...相关文章
更多- ServletOutputStream cannot be resolved to a type
- Becoming a data scientist
- Solr: a custom Search RequestHandler
- Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years
- She’s Not Carrying A Handbag
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- Fading Like a Flower - Roxette
- Drupal Forums instead of phpBB or vBulletin: A casestudy
- a favorite song
- Spring Data: a new perspective of data operations
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。