“未设置DataContext".主窗口上的消息 [英] "DataContext is not set" message on main window

查看:62
本文介绍了“未设置DataContext".主窗口上的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取XLS1106未设置DataContext".Visual Studio中我的主窗口XAML上显示消息.据我所知,我没有使用任何与此相关的东西,也没有任何问题.我只是抑制该消息,但是我不确定为什么会出现该消息.

I'm getting the XLS1106 "DataContext is not set" message on my main window XAML in Visual Studio. As far as I can tell, I haven't used anything related to that and nothing is broken. I would just supress the message, but I'm not sure why it's there.

这是我的整个XAML:

Here is my whole XAML:

<Window x:Name="MyWindow" x:Class="Whiteboard.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:Whiteboard"
        mc:Ignorable="d"
        Title="Untitled - CFWhiteboard" Height="450" Width="800" MouseDown="WindowMouseDown" MouseMove="WindowMouseMove" KeyDown="WindowKeyDown" KeyUp="WindowKeyUp" Icon="icons8-interactive-whiteboard-100.png" Loaded="WindowLoaded" Closing="WindowClosing">
    <Window.Resources>
        <ResourceDictionary>
            <FrameworkElement x:Key="CursorRectangle" Cursor="Resources/Cursors/rectangle.cur"/>
            <FrameworkElement x:Key="CursorSquare" Cursor="Resources/Cursors/lockrect.cur"/>
            <FrameworkElement x:Key="CursorEllipse" Cursor="Resources/Cursors/ellipse.cur"/>
            <FrameworkElement x:Key="CursorCircle" Cursor="Resources/Cursors/lockellipse.cur"/>
        </ResourceDictionary>
    </Window.Resources>
    <Canvas x:Name="MainCanvas"/>
</Window>

推荐答案

该消息为误报.最新的Visual Studio预览版中提供了该问题的修补程序:

The message is a false positive. The fix for the problem is available in the latest preview version of Visual Studio:

Microsoft解决方案-Bhavya Udayashankar [MSFT]已关闭-修复···

Microsoft Solution - Bhavya Udayashankar [MSFT] Closed - Fixed ···

已发布针对此问题的修复程序!从 https://visualstudio.microsoft.com/downloads/安装最新的预览版本.感谢您提供宝贵的反馈意见,以帮助改进产品.

A fix for this issue has been released! Install the most recent preview release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.

请参见问题 "在Visual Studio开发者社区站点上的原始C#WPF .Net应用程序上的XLS1106" .

See issue "XLS1106 on virgin C# WPF .Net application" on the Visual Studio Developer Community site.

在没有设置任何数据绑定的最简单的应用程序中,不需要设置数据上下文,并且可以安全地忽略给出的警告.

In the simplest applications without any data bindings set up, there is no need for a data context to be set, and the warning given can be safely ignored.

请注意,您应该不要遵循上述注释的建议,告诉您将 DataContext = this; 添加到实际应用程序的窗口构造函数中.编写适当的视图模型对象类型,然后创建该对象的实例以设置为您的 DataContext 引用.

Note that you should NOT follow the advice of the comment above telling you to add DataContext = this; to the window's constructor for real-world applications. Write a proper view model object type, and create an instance of that to set as your DataContext reference.

这篇关于“未设置DataContext".主窗口上的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆