4

새 프로젝트에 대해 caliburn.micro 프레임 워크를 사용하고 있지만 ListPicker (툴킷에서 가져온 것)를 바인딩해야합니다. 컨트롤을 간단한 DropDown으로 변경하면 모든 것이 예상대로 작동합니다. 나는 드롭 다운 때문에 기본 협약, 제대로 작동한다고 가정 here 구현 : 선택기를 구현하지 않는WP7의 ListPicker에 대한 caliburn.micro 바인딩 규칙

AddElementConvention<Selector>(Selector.ItemsSourceProperty, "SelectedItem", "SelectionChanged") 
    .ApplyBinding = (viewModelType, path, property, element, convention) => { 
     if (!SetBinding(viewModelType, path, property, element, convention)) 
      return false; 

     ConfigureSelectedItem(element, Selector.SelectedItemProperty,viewModelType, path); 
     ApplyItemTemplate((ItemsControl)element, property); 

     return true; 
    }; 

ListPicker을, 그래서 난 내 부트 스트 래퍼에서 사용자 지정 규칙을 추가하는 시도했다 :

static void AddCustomConventions() { 
    AddElementConvention<ListPicker>(ListPicker.ItemsSourceProperty, "SelectedItem", "SelectionChanged") 
     .ApplyBinding = (viewModelType, path, property, element, convention) => { 
      ConventionManager.ConfigureSelectedItem(element, ListPicker.SelectedItemProperty,viewModelType, path); 
      return true; 
     }; 
} 

아쉽게도 작동하지 않습니다. 도울 수 있니?

답변

8

나는이 문제를 해결했다.

ConventionManager.AddElementConvention<ListPicker>(ListPicker.ItemsSourceProperty, "SelectedItem", "SelectionChanged") 
    .ApplyBinding = (viewModelType, path, property, element, convention) => 
    { 
     if (ConventionManager.GetElementConvention(typeof(ItemsControl)).ApplyBinding(viewModelType, path, property, element, convention)) 
     { 
      ConventionManager.ConfigureSelectedItem(element, ListPicker.SelectedItemProperty, viewModelType, path); 
      return true; 
     } 
     return false; 
    }; 

또한, 다른 문제점이있다. 내 SelectedItem 속성이 null을 반환했지만 Items 속성에 null 값이 없습니다. 선택한 항목이 목록에 없기 때문에 유효하지 않은 예외가 있습니다.

관련 문제