问题
The Resharper intellisense does not seem to work for me in XAML My Xaml looks like
<Window x:Class="GraphicalLuaEditor.MainWindow"
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:GraphicalLuaEditor"
xmlns:nodeScriptingEditor="clr-namespace:NodeScriptingEditor;assembly=NodeScriptingEditor"
mc:Ignorable="d"
Title="MainWindow">
<DockPanel>
<TextBlock Text="{Binding Test}"/>
</DockPanel>
and my xaml.cs looks like
using System;
using System.Windows;
using System.Windows.Input;
namespace GraphicalLuaEditor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = this;
InitializeComponent();
}
public string Test { get; set; } = "ÖÖÖH";
private void CommonCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
throw new NotImplementedException();
}
}
}
When I edit the XAML I expect it to help me with the data binding by suggesting properties from the code behind but it doesn't. At work where I seemingly do nothing different it works!
Also, it complains about it Can't resolve symbol Test due to unknown data context
回答1:
Intellisense does not work for xaml binding expressions unless DataContext is set in xaml too.
if Window iteslf is used as a DataContext, the following binding can be used:
<Window DataContext="{Binding RelativeSource={RelativeSource Self}}" ...>
if there is a specialized view model, design-time DataContext can be used:
<Window d:DataContext="{d:DesignInstance Type=vm:MyViewModel, IsDesignTimeCreatable=True}" ...>
来源:https://stackoverflow.com/questions/46718171/resharper-intellisense-wont-work-for-xaml