如何使 Resharper 解析 CustomBinding MarkupExtension 的路径
我想创建一些扩展的 Binding-Markup-Extension,其行为就像普通的 WPF-Binding,但做了更多的事情(使用不同的默认值,也许添加一些行为等)。 代码如下所示:
public class CustomBindingExtension : Binding
{
.. some extra properties and maybe overrides ...
}
一切正常,包括 XAML-intellisense,但我无法使 Resharper 正确解析我的绑定路径。 即:使用此代码,我可以 [Strg]+单击“CurrentText”,Resharper 让 vs2010 导航到定义 CurrentText-Property 的代码。
<UserControl x:Name="uc" ...>
<TextBox Text="{Binding ViewModel.CurrentText, ElementName=uc}" />
</UserControl>
但是使用在运行时正常工作的 my 绑定,当我将鼠标悬停在“CurrentText”上时,我只是得到一个工具提示,告诉我这是一些“MS.Internal.Design.Metadata.ReflectionTypeNode”,并且没有通过 [ 进行导航Strg]+单击。
<UserControl x:Name="uc" ...>
<TextBox Text="{util:CustomBinding ViewModel.CurrentText, ElementName=uc}" />
</UserControl>
我尝试了以下操作:
我还查看了原始类 Binding 和 BindingBase,但找不到与我的代码有任何更多差异。 有什么想法可以帮助这里吗? 或者这只是对 Binding-MarkupExtension 的特殊处理,我自己的 MarkupExtensions 根本无法获得这种处理?
2011 年 3 月 16 日更新:也可能是 Resharper 的错误或缺陷,Jetbrains 正在调查该问题:http:// /youtrack.jetbrains.net/issue/RSRP-230607
2013 年 12 月 10 日更新:同时,该功能似乎可以正常工作(使用 R# 7.1.3,也可能是早期版本),我实际上使用该方法BindingDecoratorBase 我非常喜欢它。 也许只有当您的 MarkupExtension 以“Binding”结尾时它才有效,但我的却如此,所以我很高兴。
I want to create some extended Binding-Markup-Extension, which behaves just like a normal WPF-Binding but does some things more (use different defaults, maybe add some behavior, etc.).
Code looks like this:
public class CustomBindingExtension : Binding
{
.. some extra properties and maybe overrides ...
}
It all works fine including XAML-intellisense, except I just can't make Resharper resolve my Binding-Path correctly.
I.e.: using this code I can [Strg]+Click on 'CurrentText' and Resharper lets vs2010 navigate to the code defining the CurrentText-Property.
<UserControl x:Name="uc" ...>
<TextBox Text="{Binding ViewModel.CurrentText, ElementName=uc}" />
</UserControl>
But using my binding, which works correctly at runtime, I just get a Tooltip when hovering 'CurrentText' telling me it is some 'MS.Internal.Design.Metadata.ReflectionTypeNode', and no navigation via [Strg]+Click.
<UserControl x:Name="uc" ...>
<TextBox Text="{util:CustomBinding ViewModel.CurrentText, ElementName=uc}" />
</UserControl>
I tried the following things:
I also looked at the original classes Binding and BindingBase, but could not find any more difference to my code.
Any ideas what should help here?
Or is this just a special treatment of the Binding-MarkupExtension which I can in no way get for my own MarkupExtensions?
Update 16.03.2011: Might also be bug or deficiency of Resharper, Jetbrains is investigating the issue: http://youtrack.jetbrains.net/issue/RSRP-230607
Update 10.12.2013: Meanwhile, the feature seems to be working (with R# 7.1.3, maybe also earlier versions), I actually use the approach with the BindingDecoratorBase and I like it a lot.
Maybe it only works, if your MarkupExtension ends on 'Binding', but mine does, so I am happy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,这在当前版本的 R# 中是不可能的,并且不幸的是,仍然缺少即将发布的 R# 6.1 版本的功能。
此功能需要大量基础架构更改,但它在我们的列表中,并且肯定会在 R# 7 中实现。看起来像
[CustomBindingMarkup]
和[BindingPath]
(对于path
构造函数参数和Path
属性)属性将被引入。对于给您带来的任何不便,我们深表歉意。
Actually it's not possible in current versions of R# and, unfortunately, still be missing feature of upcoming R# 6.1 release.
This feature requires a lot of infrastructure changes, but it's on our list and definitely will be implemented in R# 7. Seems like
[CustomBindingMarkup]
and[BindingPath]
(forpath
constructor parameter and thePath
property) attributes will be introduced.We really apologize for any inconvenience.
您应该使用正确的命名空间访问自定义标记扩展:
这里是一篇关于创建自定义标记扩展的好文章。
You should access your custom Markup-Extension, using the correct namespace:
Here is a nice article about creating custom Markup-Extensions.
欺骗 R# 的一种方法是将其命名为 Binding:
然后它的工作方式与 R# 的标准绑定相同
One way to fool R# is to name it Binding:
Then it works the same as standard binding with R#