wpf - IntelliSense for Data Binding not working -
after couple of hours trying debug issue data-binding caused mistyped property in binding
extension. once noticed mistake, realization if intellisense available may have not made mistake in first place. visual studio user used error/warnings when mistyping name; perhaps i'm spoiled, lack of intellisense led error.
i did research , found intellisense data binding available visual studio 2013 i'm using (ultimate edition). tried creating simple wpf app following second example in blog. firstly, there appears error in second example in blog resulted compiler error. prefixing type=viewmodel:mainviewmodel
attribute d:
fixed compiler error, yet properties of view-model class still not showing in intellisense menu. code below , in github.
mainviewmodel.cs:
using system.componentmodel; using system.runtime.compilerservices; namespace intellisensefordatabinding { public class mainviewmodel : inotifypropertychanged { public mainviewmodel() { greeting = "hello world"; answer = 42; } private string _greeting; public string greeting { { return _greeting; } set { _greeting = value; onpropertychanged(); } } private int _answer; public int answer { { return _answer; } set { _answer = value; onpropertychanged(); } } public event propertychangedeventhandler propertychanged; protected void onpropertychanged([callermembername] string propertyname = null) { propertychangedeventhandler handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } } }
mainwindow.xaml:
<window x:class="intellisensefordatabinding.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="450" d:datacontext="{d:designinstance type=mainviewmodel, isdesigntimecreatable=true}" title="mainwindow" height="350" width="525"> <grid> </grid> </window>
mainwindows.xaml.cs:
using system.windows; namespace intellisensefordatabinding { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { datacontext = new mainviewmodel(); initializecomponent(); } } }
here's evidence not working:
i expect see item 'greeting' property in intellisense menu. suggestions on why it's not there? i've tried resetting visual studio settings default, in case.
in addition, suggestions on additional methods preventing or detected mistyped property names in binding attributes?
i opened github project in visual studio 2013 , got same behavior; no intellisense bindings.
the design data key binding resolution failing, recommend this:
- add project namespace window element:
xmlns:local="clr-namespace:intellisensefordatabinding"
can resolve location of vm. - change
d:datacontext
use thelocal
namespace instead ofd:type
, providing location of type you're trying use:d:datacontext="{d:designinstance local:mainviewmodel, isdesigntimecreatable=true}"
- clean, build, , test
proof:
Comments
Post a Comment