我在我的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