C# 可编辑的WPF组合框不激发PropertyChanged
我有一个不可编辑的组合框来显示数据库和SQL数据库的所有表C# 可编辑的WPF组合框不激发PropertyChanged,c#,wpf,combobox,propertychanged,C#,Wpf,Combobox,Propertychanged,我有一个不可编辑的组合框来显示数据库和SQL数据库的所有表 <ComboBox Grid.Column="1" Grid.Row="2" Height="23" Margin="3,3,3,3" Name="cbLogTable" VerticalAlignment="Top" ItemsSource="{
<ComboBox Grid.Column="1"
Grid.Row="2"
Height="23"
Margin="3,3,3,3" Name="cbLogTable" VerticalAlignment="Top"
ItemsSource="{Binding}"
TextSearch.TextPath="TABLE_NAME"
SelectedValue="{Binding Path=LogTable, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=TABLE_NAME}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我使用以下数据绑定填充组合框:
private void UpdateLogTable()
{
var connection = new SqlConnection(_connectionString);
connection.Open();
DataTable t = connection.GetSchema("Tables");
cbLogTable.DataContext = t;
connection.Close();
}
但是我没有收到关于更改组合框的选定值的PropertyChanged通知。我的错在哪里?在
SelectedValue
的绑定中:
SelectedValue="{Binding Path=LogTable,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
ValidatesOnDataErrors=True,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
否则,绑定将在
DataTable
类型(组合框的DataContext)上查找LogTable
属性,并以静默方式失败。是否确定LogTable
是依赖性属性?(除此之外:SqlConnection
在UI线程中???)您试图在哪里捕获propertychanged事件?
SelectedValue="{Binding Path=LogTable,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
ValidatesOnDataErrors=True,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"