The bottom line is that I can not bind in xaml model created in the viewmodel . If the model is obtained from SelectedItem ListBox 'a, then all the rules. And if through new then nothing. The code itself.

 viewmodel private CCard selectedCard; public CCard SelectedCard { get { return selectedCard; } set { selectedCard = value; OnPropertyChanged("SelectedCard"); } } private Commands selectedRegnumCommand; public Commands SelectedRegnumCommand { get { return selectedRegnumCommand ?? (selectedRegnumCommand = new Commands(obj => { selectedCard = getSelectedCard(SelectedRegnum.Regnum); })); } } 

getSelectedCard - returns a CCard object

 xaml <StackPanel x:Name="SP_cardInfo" DockPanel.Dock="Right" Width="300" DataContext="{Binding SelectedCard}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120*"/> <ColumnDefinition Width="180*"/> </Grid.ColumnDefinitions> <TextBlock Text="Номер документа:" Grid.Column="0" /> <TextBlock x:Name="Tbl_regNum" Text="{Binding SelectedCard.Regnum, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Margin="10,0,64,0" /> </Grid> </StackPanel> CCard public string Regnum { get { return _regnum; } set { _regnum = value; OnPropertyChanged("Regnum"); } } 

In the model implemented INotifyPropertyChanged . Other moments work. I understand that the problem is precisely that SelectedCard is created via new . Tell me where I'm stupid

    2 answers 2

    You set the DataContext to the StackPanel

     DataContext="{Binding SelectedCard}" 

    And then you work outside this context.

     {Binding SelectedCard.Regnum, ...} 
    • This I have tried differently. Still does not work. It was originally Text="{Binding Path=Regnum, UpdateSourceTrigger=PropertyChanged}" - Rans

    I repent, I missed the moment. I refer directly to the selectedCard field, and not through the public CCard SelectedCard method. Therefore, the field is changing, but the interface does not know about it, hence there is no binding in xaml. And also got out of context

    • Those. spoons found something, yes? :) - Artyom Okonechnikov
    • Aha, and sediment from carelessness too) - Rans