A
A
Alexey2016-04-21 10:21:28
WPF
Alexey, 2016-04-21 10:21:28

Why doesn't Binding work?

There is a ViewModel that describes the fields and methods that return them.
Fragment:

public OrdersListViewModel()
        {
            base.DisplayName = "Список заказов";
            Dat1 = DateTime.Now.AddDays(-7).Date;
            Dat2 = DateTime.Now.AddDays(3).Date;
        }

        private ObservableCollection<ViewOrderHeader> _ViewOrdelHeaderCollection;
        private DateTime _dat1;
        
       public ObservableCollection<ViewOrderHeader> ViewOrdelHeaderCollection
        {
           ...
        }

        public DateTime Dat1
        {
            get     { return _dat1;   }
            set      { _dat1 = value;    base.OnPropertyChanged("Dat1");    }
        }
     
        }

Now I display the data on the View:
<TextBlock  Text="{Binding Path=Dat1}"  /> <!--биндинг работает!!!-->
        <DataGrid ItemsSource="{Binding}" >
            <DataGrid.Columns>
                     <DataGridTextColumn>
                    <DataGridTextColumn.Header>
                        <Expander Header="Дата заказа">
                            <StackPanel Orientation="Vertical" DataContext="{Binding}">
                                <DatePicker x:Name="dpZ1A" 
                                            DisplayDate="{Binding Path=Dat1}" /> <!--Binding Не работает-->
                            </StackPanel>
                        </Expander>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
          </DataGrid>

As it was already written above, Binding does not work everywhere. Please explain where I went wrong and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2016-04-21
@k1lex

Top {Binding Path=Dat1}, bottom {Binding Path=Dt1}. Typo - missing character a.
When you run the program in the studio, diagnostic messages are often displayed in the Output window, and similar errors are displayed there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question