Home c# How to fix the error XLS1106 DataContext not set?

How to fix the error XLS1106 DataContext not set?

Author

Date

Category

When analyzing the code, such messages appear:

Below is one example of code where you need to fix this message:

& lt; window x: class = "fitnescentr.formallclient"
    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: Fitnescentr"
    MC: IGNORABLE = "D"
    Title = "Fitness-center clients" height = "481.2" width = "884.8"
    Background = "LightSlategray" & gt;
  & lt; window.triggers & gt;
    & lt; Eventtrigger RouteDevent = "window.loaded" & gt;
      & lt; beginstoryboard & gt;
        & lt; Storyboard & GT;
          & lt; DoubleAnimation Storyboard.TargetProperty = "OPACITY"
                   To = "1" duration = "00:00:22" & gt;
            & lt; doubleanimation.easingfunction & gt;
              & lt; bacsease easingmode = "Easeout" / & gt;
            & lt; /dobleonimation.easingfunction>
          & lt; / DoubleAnimation & gt;
        & lt; / StoryBoard & gt;
      & lt; / beginstoryboard & gt;
    & lt; / eventtrigger & gt;
  & lt; /window.triggers>
  & lt; window.resources & gt;
    & lt; style targettype = "TextBox" & gt;
      & lt; style.triggers & gt;
        & lt; eventtrigger routedevent = "textbox.mouseDoubleClick" & gt;
          & lt; eventtrigger.actions & gt;
            & lt; beginstoryboard & gt;
              & lt; Storyboard & GT;
                & lt; coloranimation storyboard.targetproperty = "background.color"
                    To = "DarkSeagreen" autoreverse = "true" duration = "0: 0: 2" / & gt;
              & lt; / StoryBoard & gt;
            & lt; / beginstoryboard & gt;
          & lt; /eventtrigger.actions>
        & lt; / eventtrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "label" & gt;
      & lt; setter property = "fontsize" value = "15" / & gt;
      & lt; setter property = "fontfamily" value = "Verdana" / & gt;
      & lt; setter property = "fontweight" value = "black" / & gt;
    & lt; / style & gt;
    & lt; Style targettype = "Button" & gt;
      & lt; style.triggers & gt;
        & lt; Trigger Property = "Ismouseover" value = "True" & gt;
          & lt; setter property = "fontsize" value = "14" / & gt;
          & lt; setter property = "foreground" value = "Orangered" / & gt;
        & lt; / trigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
  & lt; /window.resources>
  & lt; grid & gt;
    & lt; label content = "name" horizontalignment = "left" margin = "589,33,0,0" verticalAlignment = "TOP" / & gt;
    & lt; label content = "surname" horizontalignment = "left" margin = "589,62,0,0" verticalAlignment = "TOP" / & gt;
    & Lt; Label Content = "Middle" HorizontalAlignment = "Left" Margin = "589,93,0,0" VerticalAlignment = "Top" / & gt;
    & Lt; Label Content = "phone number" HorizontalAlignment = "Left" Margin = "589,124,0,0" VerticalAlignment = "Top" / & gt;
    & Lt; Label Content = "Birthday" HorizontalAlignment = "Left" Margin = "589,153,0,0" VerticalAlignment = "Top" / & gt;
    & Lt; Label Content = "Email" HorizontalAlignment = "Left" Margin = "589,182,0,0" VerticalAlignment = "Top" / & gt;
    & Lt; TextBox HorizontalAlignment = "Left" Height = "23" Margin = "680,34,0,0" TextWrapping = "Wrap" Text = "" VerticalAlignment = "Top" Width = "188" x: Name = "txtName" / & gt;
    & Lt; TextBox HorizontalAlignment = "Left" Height = "26" Margin = "680,62,0,0" TextWrapping = "Wrap" Text = "" VerticalAlignment = "Top" Width = "188" x: Name = "txtSurname" / & gt; 
& lt; TextBox horizontalignment = "left" height = "26" margin = "680,93,0,0" TextWrapping = "Wrap" text = "" verticalAlignment = "top" width = "188" x: name = "txtfather" / & gt;
    & lt; textbox horizontalignment = "left" height = "23" margin = "737,124,0,0" textwrapping = "wrap" text = "" verticalalignment = "top" width = "131" x: name = "TXTNUMPHONE" / & gt ;
    & lt; textbox horizontalignment = "left" height = "24" margin = "737,153,0,0" TextWrapping = "Wrap" text = "" verticalAlignment = "TOP" width = "131" x: name = "txtatebirth" / & gt ;
    & lt; textbox horizontalignment = "left" height = "24" margin = "650,182,0,0" TextWrapping = "Wrap" text = "" verticalAlignment = "TOP" width = "218" x: name = "txtmailpost" / & gt ;
    & lt; calendar horizontalignment = "left" margin = "697,257,0,0" verticalignment = "top" background = "lightgray" borderbrush = "dimgray" x: name = "calendarfordata" selecteddateschanged = "calendar_changed" height = "164" width = "171" / & gt;
    & lt; label content = "floor" horizontalignment = "left" margin = "589,211,0,0" verticalignment = "TOP" / & gt;
    & lt; textbox horizontalignment = "left" height = "23" margin = "637,211,0,0" TextWrapping = "Wrap" text = "" verticalAlignment = "TOP" width = "231" x: name = "txtsex" / & gt ;
    & lt; button content = "Create" horizontalignment = "left" margin = "602,296,0,0" verticalAlignment = "top" width = "75" click = "adddate_click" background = "White" / & gt;
    & lt; Button content = "Update" horizontalignment = "left" margin = "602,320,0,0" verticalAlignment = "top" width = "75" click = "btnupdate_click" background = "White" / & gt;
    & lt; Button content = "Delete" horizontalignment = "left" margin = "602,368,0,0" verticalAlignment = "Top" width = "75" click = "btndelete_click" background = "White" / & gt;
    & lt; button content = "change" horizontalignment = "left" margin = "602,344,0,0" verticalalignment = "top" width = "75" click = "btnchanged_click" background = "White" / & gt;
    & lt; label content = "№" horizontalignment = "left" margin = "589,4,0,0" verticalignment = "top" rendertransformorigin = "0.558.0.106" / & gt;
    & lt; textbox horizontalignment = "left" height = "18" margin = "626,10,0,0" TextWrapping = "Wrap" text = "" verticalAlignment = "TOP" width = "242" x: name = "txtporydk" / & gt;
    & lt; DataGrid horizontalignment = "left" height = "438" margin = "10,4,0,0" verticalAlignment = "Top" width = "574" name = "gridforclint" / & gt;
  & lt; / grid & gt;
& lt; / window & gt;

How to fix all this message? Can I hide these messages?


Answer 1, Authority 100%

This is not an error, but an informational message. You can ignore it. Most likely, it comes from some kind of code analyzer. To install, add DataContext = this in the form constructor in C # and reset the application.

But the best thing is to study what kind of data binding via Binding , there and learn about what DataContext is, and with what it is eaten.


Bonus

Your markup, only without war with MARDZHINS. Observe what yes as. Make interfaces will be much easier. And yes, here you can not lock the size of the window, but only set it minwidth and minheight , the size of the table will vary depending on the window size automatically.

& lt; window.triggers & gt;
  & lt; Eventtrigger RouteDevent = "window.loaded" & gt;
    & lt; beginstoryboard & gt;
      & lt; Storyboard & GT;
        & lt; DoubleAnimation Storyboard.TargetProperty = "OPACITY"
                  To = "1" duration = "00:00:22" & gt;
          & lt; doubleanimation.easingfunction & gt;
            & lt; bacsease easingmode = "Easeout" / & gt;
          & lt; /dobleonimation.easingfunction>
        & lt; / DoubleAnimation & gt;
      & lt; / StoryBoard & gt;
    & lt; / beginstoryboard & gt;
  & lt; / eventtrigger & gt;
& lt; /window.triggers>
& lt; window.resources & gt;
  & lt; style targettype = "TextBox" & gt;
    & lt; setter property = "margin" value = "5" / & gt;
    & lt; style.triggers & gt;
      & lt; eventtrigger routedevent = "textbox.mouseDoubleClick" & gt;
        & lt; eventtrigger.actions & gt;
          & lt; beginstoryboard & gt;
            & lt; Storyboard & GT; 
& lt; coloranimation storyboard.targetproperty = "background.color"
                  To = "DarkSeagreen" autoreverse = "true" duration = "0: 0: 2" / & gt;
            & lt; / StoryBoard & gt;
          & lt; / beginstoryboard & gt;
        & lt; /eventtrigger.actions>
      & lt; / eventtrigger & gt;
    & lt; /style.triggers>
  & lt; / style & gt;
  & lt; style targettype = "textblock" & gt;
    & lt; setter property = "fontsize" value = "15" / & gt;
    & lt; setter property = "fontfamily" value = "Verdana" / & gt;
    & lt; setter property = "fontweight" value = "black" / & gt;
    & lt; setter property = "margin" value = "5" / & gt;
    & lt; setter property = "verticalignment" value = "center" / & gt;
  & lt; / style & gt;
  & lt; Style targettype = "Button" & gt;
    & lt; style.triggers & gt;
      & lt; Trigger Property = "Ismouseover" value = "True" & gt;
        & lt; setter property = "fontsize" value = "14" / & gt;
        & lt; setter property = "foreground" value = "Orangered" / & gt;
      & lt; / trigger & gt;
    & lt; /style.triggers>
  & lt; / style & gt;
& lt; /window.resources>
& lt; grid & gt;
  & lt; grid.columndefinitions & gt;
    & lt; columndefinition / & gt;
    & lt; columndefinition width = "300" / & gt;
  & lt; /grid.columndefinitions>
  & lt; datagrid margin = "5" name = "gridforclint" / & gt;
  & lt; stackpanel orientation = "vertical" grid.column = "1" margin = "5" & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock text = "« «/ & gt;
      & lt; TextBox X: Name = "TXTPORYDK" / & GT;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Name" / & gt;
      & lt; TextBox X: name = "TXTNAME" / & GT;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Surname" / & gt;
      & lt; TextBox X: Name = "TxtSurname" / & gt;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Patronymic" / & gt;
      & lt; TextBox X: Name = "Txtfather" / & gt;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "phone number" / & gt;
      & lt; TextBox X: name = "TXTNUMPHONE" / & GT;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Birthday" / & gt;
      & lt; TextBox X: name = "txtDatebirth" / & gt;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Email" / & gt;
      & lt; TextBox X: name = "TXTMailPost" / & gt;
    & lt; / dockpanel & gt;
    & lt; DockPanel & GT;
      & lt; TextBlock Text = "Paul" / & gt;
      & lt; ComboBox X: Name = "Combosex" margin = "5" & gt;
        & lt; ComboBoxItem & GT; Male & Lt; / ComboBoxItem & GT;
        & lt; ComboBoxItem & gt; female & lt; / ComboBoxItem & gt;
      & lt; / ComboBox & GT;
    & lt; / dockpanel & gt;
    & lt; grid & gt;
      & lt; grid.columndefinitions & gt;
        & lt; columndefinition / & gt;
        & lt; columndefinition width = "auto" / & gt;
      & lt; /grid.columndefinitions>
      & lt; calendar grid.column = "1" margin = "5" Background = "LightGray" borderbrush = "dimgray" x: name = "calendarfordata" selecteddateschanged = "calendar_changed" height = "164" width = "171" / & gt;
      & lt; stackpanel orientation = "vertical" verticalalignment = "center" & gt;
        & lt; stackpanel.resources & gt;
          & lt; Style targettype = "Button" & gt;
            & lt; setter property = "margin" value = "5.2" / & gt;
            & lt; setter property = "width" value = "75" / & gt;
            & lt; setter Property = "Padding" value = "5" / & gt;
            & lt; setter property = "background" value = "White" / & gt;
          & lt; / style & gt;
        & lt; /stackpanel.resources>
        & lt; Button content = "Create" Click = "AddDate_Click" / & gt;
        & lt; button content = "update" click = "btnupdate_click" / & gt;
        & lt; button content = "Delete" click = "btndelete_click" / & gt;
        & lt; button content = "change" click = "btnchanged_click" / & gt;
      & lt; / stackpanel & gt;
    & lt; / grid & gt;
  & lt; / stackpanel & gt;
& lt; / grid & gt;

p.s. Do not use LABEL in WPF, use TextBlock . It works easier and faster.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions