我在我的xaml中使用ComboBox,但是我无法看到视图上的任何数据。它只显示空文本文件和空白下拉菜单。如何调试并解决ComboBox的绑定问题?
我试图在these tips的帮助下调试该问题。但是,我一直无法解决这个问题。
这里的databindingDebugConverter:
public class DatabindingDebugConverter : IValueConverter
{
public object Convert(object value1, Type targetType, object parameter, CultureInfo culture)
{
Debugger.Break();
return value1;
}
public object ConvertBack(object value2, Type targetType, object parameter, CultureInfo culture)
{
Debugger.Break();
return value2;
}
}
- 数值1的组合框
Text=
情况下返回"Field Device"
(object{string})
- 并在
ItemsSource=
数值1返回object{Device}
与Category
领域和借鉴Category1
持有CategoryId
的对象。 - 对于
SelectedValue
a"Field Device"
(object{string})
再次返回。
这里是ComboBox XAML:
<ComboBox x:Name="ProductCategoryComboBox" HorizontalAlignment="Right" Height="21.96" Margin="0,20,10.5,0" VerticalAlignment="Top" Width="100"
Text="{Binding DeviceDatabaseViewModel.SelectedDevice.Category, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource debugConverter}}"
IsEditable="False"
ItemsSource="{Binding DeviceDatabaseViewModel.SelectedDevice, Converter={StaticResource debugConverter}}"
SelectedValue="{Binding DeviceDatabaseViewModel.SelectedDevice.Category, Mode=TwoWay, Converter={StaticResource debugConverter}}"
SelectedValuePath="CategoryId"
DisplayMemberPath="Category" />
相似的结合,包括XAML中TextBlock
领域工作正常,并从SelectedDevice
显示字符串值。
编辑
的selectedDevice
从dataGrid
简称:
private Device _selectedDevice;
public Device SelectedDevice
{
get
{
return _selectedDevice;
}
set
{
if (_selectedDevice == value)
{
return;
}
_selectedDevice = value;
RaisePropertyChanged("SelectedDevice");
}
}
啊对了,忘了,我需要收集的'itemsSource' – ajr