0

我有一个与 of 相关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;
    }
}

这是什么原因。请帮我解决我的问题。

4

1 回答 1

0

您是否尝试过将绑定更改为静态资源,类似的

<ComboBox Name="cbUsgSrc"  
          ItemsSource="{StaticResource UsgSrcUOMS}" 
          SelectedValue="{Binding Path=UsgSrc}" 
          SelectedValuePath="UtType" 
          DisplayMemberPath="UtType">
</ComboBox>
于 2013-03-28T17:37:56.350 回答