I've created a custom MarkupExtension
that allows an easy way to to forward events from FrameworkElements
to methods on the view-model. Everything works perfectly, except Visual Studio doesn't provide any Intellisense when filling in the XAML. Is there any way that I can provide Visual Studio with the information it needs to provide Intellisense?
The MarkupExtension
:
public class VmCall : MarkupExtension
{
public string ActionName { get; }
public VmCall(string actionName)
{
ActionName = actionName;
}
//.....
}
The view-model:
class TestWindowVm : ViewModel
{
public void Click()
{
MessageBox.Show("Click!");
}
}
Using the MarkupExtension
in XAML:
<Window
x:Class="WpfLib.Tests.VmCallMarkupExtension.TestWindow"
xmlns:wpfLib="clr-namespace:AgentOctal.WpfLib;assembly=WpfLib"
//Many xmlns and attributes left out of example for brevity.
d:DataContext="{d:DesignInstance TestWindowVm}"
mc:Ignorable="d">
<Button Click="{wpfLib:VmCall Click}"/>
</Window>
Ideally, when the user presses the space-bar after "VmCall", Intellisense should present them with a list of all the methods on the current element's DataContext
(Just Click
on TestWindowVm
in this specific example).
If there is some way to make this work, based on previous experience with WinForms, I would expect some kind of Attribute
I could place on the arguments of the constructor for VmCall
that informs Visual Studio how to generate the intellisense for that argument. So far, I haven't been able to find anything like that. I'm not sure if I'm actually looking for the wrong thing, or if this in't possible to do at all. If it matters, I'm mainly interested in Visual Studio 2017.
I've looked at all the attributes listed in System.Windows.Markup
, and nothing obvious jumped out at me.