2014-03-24 2 views
1

WPF Datagrid의 DataGridTemplateColumn에 문제가있어 사용자 상호 작용에 기반하여 ComboBox에 표시되는 항목을 업데이트하고 있습니다. 프로그램이 데이터베이스에 바인딩되어 있기 때문에 데이터베이스의 모든 항목을 한 번에로드하는 대신 해당 항목에서 Entity Framework를 사용하여 사용자가 요청한 항목을 가져옵니다.Datagrid Custom Combobox가 업데이트되지 않습니다.

컴팩트 한보기를 용이하게하기 위해 다음/이전 단추가 콤보 상자 템플릿뿐 아니라 검색 기능에도 적용됩니다. 실행중인 문제는 다음과 같습니다.템플릿이있는 콤보 상자가 DataGrid에 있으면 다음/이전 작동하지 않습니다. 데이터 그 림 외에도 제대로 작동합니다.

나는 콤보 박스가 있다는 지식을 사용하여 시도해 보았고 그 콤보 박스를 이름으로 검색하여 수동으로 시각적 트리에서 가져 와서 itemssource에 대한 바인딩을 풀어 업데이트하도록했다. 아무 반응이 없습니다. 여기

내가 아래 무엇을 의미하는지의 이미지입니다 : enter image description here

디스플레이는 업데이 트를합니까 나는 새로운 셀을 선택하면, 그러나 편집 모드로 들어가고 선택한 항목을 포함하도록 목록을 업데이트 할 때 캡처하기 때문에 (바인딩을 위해 ComboBoxes는 항목 세트에없는 선택된 항목을 갖고 싶지 않습니다.)

상상할 수 있습니다. 이것은 다소 큰 문제입니다. 해결안이 발견 될 때까지 계속 개발하기가 어렵습니다. 이것이 Datagrids의 알려진 이슈입니까? 그렇다면 내 자신을 굴려야 할 수도 있습니다. MVRS 전문가가 아니기 때문에 성능상의 이유로 UI를 사용하지 않는 것은 UI 자체가 기본적으로 자체를 정의하는 것입니다. 주위

private static void UpdateComboDropdown(string comboboxName, DataGrid dataGrid) 
{ 
    /* * 
    * I think CurrentItem is used in this instance because 
    * it's a single cell selection mode? 
    * * 
    * I CBA to check. 
    * */ 
    var selectedRow = dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.CurrentItem) as DataGridRow; 
    if (selectedRow != null) 
    { 
     DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(selectedRow); 
     if (presenter != null) 
     { 

      var visualComboBox = presenter.FindChild<ComboBox>(comboboxName); 
      if (visualComboBox != null) 
      { 
       var binding = visualComboBox.GetBindingExpression(ComboBox.ItemsSourceProperty); 
       if (binding != null) 
        binding.UpdateTarget(); 
      } 
      var popupPart = visualComboBox.FindChild<Popup>("PART_Popup"); 
      if (popupPart != null && popupPart.Child != null) 
      { 
       //Popup has one child, reports zero children, so: search on its child. 
       var previous = popupPart.Child.FindChild<Button>("PreviousButton"); 
       if (previous != null) 
       { 
        var previousIsEnabledBinding = previous.GetBindingExpression(Button.IsEnabledProperty); 
        if (previousIsEnabledBinding != null) 
         previousIsEnabledBinding.UpdateTarget(); 
       } 
       var next = popupPart.Child.FindChild<Button>("NextButton"); 
       if (next != null) 
       { 
        var nextIsEnabledBinding = next.GetBindingExpression(Button.IsEnabledProperty); 
        if (nextIsEnabledBinding != null) 
         nextIsEnabledBinding.UpdateTarget(); 
       } 
      } 
     }; 
    } 
} 

내가 콤보 상자의 ItemsSource를 업데이트를 말하고 있었다 아닌 다른 방법 : 내가 바보 야

답변

0

, 그게 문제입니다. 관계가 자동으로 업데이트되지 않는 이유는 무엇입니까? 이제 드롭 다운에서 콤보 상자 컨트롤의 구성 요소를 업데이트하는 방법을 찾으십시오. PART_Popup을 얻은 다음, 다음/이전 버튼과 각각의 바인딩을 가져올 가능성이 높습니다. 이것은 성가신 일입니다.

편집 : 전체 솔루션으로 답변을 업데이트했습니다.

관련 문제