How to make Resharper resolve path for CustomBinding MarkupExtension

前端 未结 3 1319
南方客
南方客 2021-02-06 20:32

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,

相关标签:
3条回答
  • 2021-02-06 20:51

    One way to fool R# is to name it Binding:

    public class Binding : MarkupExtension
    {
        public Binding()
        {
        }
    
        public Binding(string path)
        {
            Path = path;
        }
    
        public string Path { get; set; }
    
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return 5;
        }
    }
    

    Then it works the same as standard binding with R#

    <TextBlock Text="{custom:Binding SomeProp}" />
    
    0 讨论(0)
  • 2021-02-06 21:00

    You should access your custom Markup-Extension, using the correct namespace:

    <UserControl x:Name="uc" ...
    xmlns:ext="clr-ns:YourProjectNamespace">
      <TextBox Text="{ext:CustomBinding ViewModel.CurrentText, ElementName=uc}" />
    </UserControl>
    

    Here is a nice article about creating custom Markup-Extensions.

    0 讨论(0)
  • 2021-02-06 21:01

    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] (for path constructor parameter and the Path property) attributes will be introduced.

    We really apologize for any inconvenience.

    0 讨论(0)
提交回复
热议问题