Reputation: 80
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.
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>
Upvotes: 3
Views: 1786
Reputation: 70691
The message is a false positive. The fix for the problem is available in the latest preview version of Visual Studio:
Microsoft Solution - Bhavya Udayashankar [MSFT] Closed - Fixed ···
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.
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.
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.
Upvotes: 5