AvaloniaUI / AvaloniaVS

Visual Studio Extension for Avalonia
MIT License
424 stars 82 forks source link

Autocomplete of binding properties doesn't work in Visual Studio 2022 mostly #462

Closed ProviceUnify closed 6 months ago

ProviceUnify commented 6 months ago

Describe the bug

This issue duplicated from Avalonia repo

Autocomplete Ctrl + Space for < ...={Binding ...} .../> doesn't work in Visual Studio 2022 mostly. It works in simple solutions, in some other solutions but it is unable yo use this feature in some other solutions. image

Code of AlgorithmsViewModel.cs:

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace Namespace.ViewModels.Pages
{
    public partial class AlgorithmsViewModel : ViewModelBase
    {
        [ObservableProperty]
        private string _pageName = "Algorithm View Model!";

        [RelayCommand]
        private void ButtonBindingTest()
        {
            PageName = "Algorithm View Model Changed !111!";
        }
    }
}

Code of AlgorithmsView.cs

<UserControl xmlns=         "https://github.com/avaloniaui"
             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"
             mc:Ignorable=  "d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class=       "Namespace.Views.Pages.AlgorithmsView"

             Tag=           "ALG"

             xmlns:vm=      "using:Namespace.ViewModels.Pages"

             x:DataType=    "vm:AlgorithmsViewModel">
  <Design.DataContext>
    <vm:AlgorithmsViewModel/>
  </Design.DataContext>
  <StackPanel>
    <TextBlock>Algorithms View!</TextBlock>
    <TextBlock Text="{Binding PageName}"/> <!-- HERE AUTOCOMPLETE DOESN'T APPEAR -->
    <Button Command="{Binding ButtonBindingTestCommand}">Press me!</Button> <!-- HERE AUTOCOMPLETE DOESN'T APPEAR -->
  </StackPanel>
</UserControl>

Code of MainView.cs (part)

<UserControl xmlns=         "https://github.com/avaloniaui"
             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:vm=      "using:Namespace.ViewModels"
             mc:Ignorable=  "d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class=       "Namespace.Views.MainView"

             xmlns:cnvrt=   "using:Namespace.Resources.Converters"

             xmlns:ui=      "using:FluentAvalonia.UI.Controls"
             xmlns:fi=      "using:FluentIcons.Avalonia"

             x:DataType="vm:MainViewModel">

  <Design.DataContext>
    <vm:MainViewModel/>
  </Design.DataContext>
...
    <Grid ColumnDefinitions="* *"
          RowDefinitions="Auto"
          VerticalAlignment="Center">
      <Border>

        <StackPanel Grid.Column="0"
                    Orientation="Horizontal">

          <Image Source="/Assets/Logo.png"
                 Height="40"
                 Margin="12 4"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Center" />
          <StackPanel Margin="0,0,0,0"
                      VerticalAlignment="Center"
                      Orientation="Vertical">
            <TextBlock FontSize="20"
                       FontWeight="Bold"
                       Foreground="DarkGray"
                       Text="Text" />
            <TextBlock FontSize="11"
                       FontWeight="Light"
                       Text="{Binding GuiLocalization[TitleDescription], Converter={StaticResource l18n_mnemonica}}"/> <!-- HERE AUTOCOMPLETE WORKS -->
          </StackPanel>
...

Code of MainViewModel.cs

using System.Collections.Generic;

using CommunityToolkit.Mvvm.ComponentModel;

namespace Namespace.ViewModels;

public partial class MainViewModel : ViewModelBase
{
    [ObservableProperty]
    private static Dictionary<string, string> _guiLocalization = new()
        {
            { "TitleDescription", "{120.TITLE_DESCRIPTION}" }
        };
}

To Reproduce

  1. Create Avalonia template project
  2. Create structure of project like in Description section above
  3. Add property (public type name => "value" or using [ObservableProperty] - not matter)
  4. Go to connected ...ViewModel.cs and try to use Binding autocomplete Ctrl + Space

Expected behavior

See variant of user defined props bottom: image

BUT

Got empty list with default entries (here i have defined PageName prop in ViewModel also): image

AvaloniaVS plugin version

11.5

Avalonia version

11.0.10 - 11.1.0-beta1

Visual Studio version

17.9.5

Relevant log output

09:18:35.381 [Information] 0 Starting previewer process for '"D:\Software_Git\prg\Executable\reponame-avalonia\App.Desktop\bin\Debug\net8.0\App.Desktop.dll"'
09:18:35.406 [Information] 23672 Started previewer process for '"D:\Software_Git\prg\Executable\reponame-avalonia\App.Desktop\bin\Debug\net8.0\App.Desktop.dll"'. Waiting for connection to be initialized.
09:18:35.649 [Information] 23672 Connection initialized

Additional context

I already used:

  1. Building project/solution - i have another large project where autocomplete is working
  2. Clearing Intellisense cache by extension
  3. Recreating "cursed" files - seems like working but until 1 new prop
  4. Creating new project and transfering files and code to it

I have:

  1. Set x:DataType in .axaml header
  2. Set Design.DataContext in .axaml header
  3. Double-, Triple- and Quadruple checked all paths, namespaces etc. It works sometimes but stops at randomly without any chanes so paths and other params are true
ProviceUnify commented 6 months ago

Closed as duplicate