我有观察/问题/问题。
在我的应用程序中,我加载了一个 EF 对象列表(我们称它们为“Car”),我将其设置为“ItemsControl”的“DataContext”。ItemsControl 有一堆控件,代表对象(“汽车”)的属性,如文本框和类似的......
据我了解,如果我将一个属性分配给一个控件,它应该被绑定,如果我更改 TextBox 中的值,它也应该在 Object.xml 中更改。但这在我的应用程序中没有发生。我错过了什么吗?
据我所知,相反,当从 Object-> GUI 发生更改时,属性的类需要实现接口“INotifyPropertyChanged”,但是当从 GUI-Object 发生更改时,不需要执行任何类似的操作.
我是否遗漏了某些东西,我是否误传了信息,或者只是编写了错误的代码?
已编辑 - 第一次- thnx 的建议
<ItemsControl Name="icRoles" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Name="grdRoles" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="40" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1.4*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--Subject-->
<Label Content="Uloga" Grid.ColumnSpan="2" Height="28" HorizontalAlignment="Center" Name="label8" VerticalAlignment="Center" />
<Label Content="ID:" Grid.Row="1" Height="28" Name="label1" VerticalAlignment="Top" />
<Label Content="Ime Uloge:" Grid.Row="2" Height="28" Name="label2" VerticalAlignment="Top" />
<Label Content="Prikazano ime:" Grid.Row="3" Height="28" Name="label3" VerticalAlignment="Top" />
<Label Content="Tip Uloge:" Grid.Row="4" Height="28" Name="label4" VerticalAlignment="Top" />
<Label Content="Datum Stvaranja:" Grid.Row="5" Height="28" Name="label5" VerticalAlignment="Top" />
<Label Content="Datum promjene:" Grid.Row="6" Height="28" Name="label6" VerticalAlignment="Top" />
<Label Content="Stanje:" Grid.Row="7" Height="28" Name="label7" VerticalAlignment="Top" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" Text="{Binding ID}" IsEnabled="False" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" Text="{Binding Name}" />
<TextBox Grid.Column="1" Grid.Row="3" Height="23" Text="{Binding Text}" />
<WrapPanel Grid.Column="1" Grid.Row="4" Height="25" />
<DatePicker Grid.Column="1" Grid.Row="5" Height="25" SelectedDate="{Binding DateCreated}" IsEnabled="False" />
<DatePicker Grid.Column="1" Grid.Row="6" Height="25" SelectedDate="{Binding DateModified}" IsEnabled="False" />
<CheckBox Grid.Column="1" Grid.Row="7" Height="16" IsChecked="{Binding active}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
已编辑 - 第二次 我现在已经将绑定的模式设置为控件,因为它们应该是。但是一件奇怪的事情正在发生。我已将两个文本框的绑定设置为
Text="{Binding Path=Name, Mode=TwoWay}"
Text="{Binding Path=Text, Mode=TwoWay}"
但只有第一个被设置为属性。第一个保持为空。+