我遇到一个与ComboBox
DataGrid
相关的问题。数据具有绑定性,但绑定后未显示在ComboBox
中。我的代码如下:
<my:DataGridTemplateColumn Header="UsgSrc">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cbUsgSrc"
ItemsSource="{Binding Source={StaticResource UsgSrcUOMS}}"
SelectedValue="{Binding Path=UsgSrc}"
SelectedValuePath="UtType"
DisplayMemberPath="UtType">
</ComboBox>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
静态资源代码:
UsgSrcUOMS.ObjectDataProvider UsageSrcUOMS = null;
UsageSrcUOMS = (ObjectDataProvider)FindResource("UsgSrcUOMS");
UsageSrcUOMS.ObjectInstance = objUtView;
Microsoft.Windows.Controls.DataGridCell cell = obj.GetCell(dgMtrHdr, J, 11);
if (cell != null)
{
ContentPresenter panel = cell.Content as ContentPresenter;
if (panel != null)
{
ComboBox cmbUsUtilit = obj.GetVisualChild<ComboBox>(panel);
cmbUsUtilit.IsEnabled = true;
if(objUtView!=null)
cmbUsUtilit.ItemsSource = objUtView;cmbUsUtilit.SelectedIndex=2;
}
}
这是什么原因。请帮我解决我的问题。
答案 0 :(得分:0)
您是否尝试将Binding更改为StaticResource,类似
<ComboBox Name="cbUsgSrc"
ItemsSource="{StaticResource UsgSrcUOMS}"
SelectedValue="{Binding Path=UsgSrc}"
SelectedValuePath="UtType"
DisplayMemberPath="UtType">
</ComboBox>