After a couple of hours trying to debug an issue with data-binding that was caused by a mistyped property in a Binding
extension. Once I noticed the mistake, the realization that if IntelliSense was available I may have not made the mistake in the first place. As a Visual Studio user who is used to error/warnings when mistyping a name; perhaps I'm spoiled, but the lack of IntelliSense led to the error.
I did some research and I found that Intellisense for Data Binding is available is Visual Studio 2013 which I'm using (Ultimate edition). I tried creating a simple WPF app following the second example in the blog. Firstly, There appears to be an error in the second example in the blog that resulted compiler error. Prefixing the Type=ViewModel:MainViewModel
attribute with d:
fixed the compiler error, yet the properties of my View-Model class are still not showing in the Intellisense menu. My code is below and 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
{
get { return _Greeting; }
set { _Greeting = value; OnPropertyChanged(); }
}
private int _Answer;
public int Answer
{
get { 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 for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new MainViewModel();
InitializeComponent();
}
}
}
Here's the evidence that is not working:
I would expect to see an item for the 'Greeting' property in the IntelliSense menu. Any suggestions on why it's not there? I've also tried resetting the Visual Studio settings to default, just in case.
In addition, any suggestions on additional methods for preventing or detected mistyped property names in Binding attributes?