2017-10-12 51 views
1

工作似乎ReSharper的智能感知不适合我在XAML工作 我的XAML看起来像ReSharper的智能感知不会为XAML

<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> 

和我xaml.cs看起来像

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(); 
     } 
    } 
} 

当我编辑XAML时,我期望它能通过从代码后面提示属性来帮助我实现数据绑定,但事实并非如此。在我看起来没有什么不同的工作中,它起作用!
此外,它抱怨它无法解析符号测试由于未知的数据上下文

+0

我从来没有找到Resharper与XAML合作。我遇到了类似的问题,无法找到明确的解决方案。授予我没有看起来很难。我发现如果我建立这个项目,它有时会(随机)导致resharper更好地工作。 –

+1

如果使用代码隐藏来设置'DataContext',则不会得到任何智能感知。如果它没有在XAML中看到它,那么它将不知道你想要什么。所有这些都可以通过使用MVVM来弥补。您将从设计师和Resharper那里获得智能感知。 – Laith

+0

@Lith我如何设置MVVM?你有任何链接到有用的资源或例子 – Hampus

回答

2

Intellisense不适用于xaml绑定表达式除非DataContext也设置在xaml中。

如果窗口iteslf用作一个DataContext,下面的结合可以使用:

<Window DataContext="{Binding RelativeSource={RelativeSource Self}}" ...> 

,如果有一个专门的视图模型,设计时的DataContext可以使用:

<Window d:DataContext="{d:DesignInstance Type=vm:MyViewModel, IsDesignTimeCreatable=True}" ...>