No matter how I install it - it does not work! :( Suppose:

<UserControl x:Class="CWServer.Views.MainView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CWServer" xmlns:viewModels="clr-namespace:CWServer.ViewModels" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" DataContext="JobService"> <!-- CWServer.ViewModels.JobService --> <Grid> <TextBlock Text="{Binding Path=TestProperty}"/> </Grid> </UserControl> 

Nothing derives ...

Ahh, everything I found

 <UserControl.DataContext> <viewModels:JobService/> </UserControl.DataContext> 

But why can't I use a shorter recording ???

 DataContext="{x:Type viewModels:JobService}" 
  • because it is not a short entry. DataContext is bound to the instance (or assigned). You assign this model a type of view model by this record - vitidev
  • @vitidev and for what there such attribute exists? Maybe you need to specify another markup extension? Or something else ... - PECHAIRTER
  • And by the way, but with this record (first), what is the chtoli instance created? I understand correctly? - PECHAPTER
  • attribute exists to indicate type. For example, you can in styles TargetType, useful when binding Radio to Enum yet. Yes, a lot of places, although not everywhere you need to specify the full record. - vitidev
  • Yes. <viewModels: JobService /> creates an instance with an empty constructor and assigns it to a DataContext. Because of the need to create an instance of the view model and transfer the DataContext into it, set in the code - vitidev

0