I'm not getting intellisense suggestions for properties that were source generated by the MVVM community toolkit. Is there a way to fix this? If I can't get the suggestions to work, then using [ObservableProperty] isn't even worth it IMO. Example below.
ViewModel has one source generated property and one handmade property:
public partial class SimplisticViewModel : ObservableObject
{
[ObservableProperty]
private int sourceGeneratedProperty;
private float handmadeProperty;
public float HandmadeProperty
{
get => handmadeProperty;
set => SetProperty(ref handmadeProperty, value);
}
}
XAML:
<Window x:Class="WPFEFTest.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFEFTest"
mc:Ignorable="d"
Title="TestWindow" Height="450" Width="800">
<Window.DataContext>
<local:SimplisticViewModel/>
</Window.DataContext>
<StackPanel>
<TextBox Text=""/>
</StackPanel>
</Window>
When setting up binding for the handmade property, the suggestions work:
When setting up binding for the source generated property, there are no suggestions:
However, if I write the entire property name (avoiding typos and such...) and hover my cursor over it (cursor not visible in screenshot), intellisense will correctly show the type of the property. So the problem probably isn't that intellisense doesn't "see" the property at all.
EDIT: To make it clear I'm not trying to bind to a field, below is code that MVVM community toolkit generates because of the ObservableProperty attribute:
public partial class SimplisticViewModel
{
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Toolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "7.1.0.0")]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public int SourceGeneratedProperty
{
get => sourceGeneratedProperty;
set
{
if (!global::System.Collections.Generic.EqualityComparer<int>.Default.Equals(sourceGeneratedProperty, value))
{
OnPropertyChanging(global::Microsoft.Toolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedOrChangingArgs.SourceGeneratedPropertyPropertyChangingEventArgs);
sourceGeneratedProperty = value;
OnPropertyChanged(global::Microsoft.Toolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedOrChangingArgs.SourceGeneratedPropertyPropertyChangedEventArgs);
}
}
}
}


