2011-09-01 6 views
1

을 사용하는 경우 BindableCollection을 지우는 데 문제가 있습니다. Caliburn micro를 사용하는 경우 콤보 상자가 데이터 바인딩되는 목록을 지우면 프레임 워크가 예외 (System.String에 대한보기를 찾을 수 없음)를 통해 문제가 발생합니다. 그것의 사용시 오류Combobox에 대한 datanbound

<ComboBox x:Name="Mappings" MinWidth="200"></ComboBox> 

이 모델 내가 ListView를하거나 ItemsControl에에 콤보 상자를 변경할 경우 작동

public BindableCollection<MappingSettingModel> Mappings { get; set; } 
public MappingSettingModel SelectedMapping 
{ 
    get { return selectedMapping; } 
    set 
    { 
     selectedMapping = value; 
     NotifyOfPropertyChange(() => SelectedMapping); 
    } 
} 

, 왜 내가 어떻게해야합니까 문자열하지만 뷰 모델

XAML에 바인딩되지 콤보 박스?

내가 SelectedMapping 속성을 제거하지만 내가 필요로하는 경우 작동하는지 내가 shouldbe 선택 itemn하는 설정할 수 있도록 ..

+0

지우지 않고 null로 설정하려고 했습니까? –

+0

Didify 도움이 유일한 도움이 유일한 속성에서 NotifyOfPropertyChange를 제거하는 것입니다. 하지만 코드에서 해당 속성을 설정 한 이후로 나는 그럴 수 없습니다 ... – Anders

+0

SL 또는 WP7 용입니까, 규칙을 사용하지 않고도 제대로 작동합니까? –

답변

0

내 뷰 모델 :

[Export(typeof(MiscViewModel))] 
    public class MiscViewModel : ScreenEx 
    { 
     public MiscViewModel() 
     { 
      DisplayName = "MiscViewModel Sample"; 
     } 

     private BindableCollection<MyItem> _myItems; 
     public BindableCollection<MyItem> MyItems 
     { 
      get { return _myItems; } 
      set 
      { 
       _myItems = value; 
       NotifyOfPropertyChange(() => MyItems); 
      } 
     } 

     // public BindableCollection<MyItem> MyItems { get; set; } 

     private MyItem _selectedMyItem; 
     public MyItem SelectedMyItem 
     { 
      get { return _selectedMyItem; } 
      set 
      { 
       _selectedMyItem = value; 
       NotifyOfPropertyChange(() => SelectedMyItem); 
      } 
     } 

     public void Load() 
     { 
      MyItems = new BindableCollection<MyItem> 
          { 
           new MyItem 
            { 
             MyItemName = "Item 1", 
             MyItemData = "test1" 
            }, 
           new MyItem 
            { 
             MyItemName = "Item 2", 
             MyItemData = "test2" 
            }, 
           new MyItem 
            { 
             MyItemName = "Item 3", 
             MyItemData = "test3" 
            }, 
           new MyItem 
            { 
             MyItemName = "Item 4", 
             MyItemData = "test4" 
            } 
          }; 
     } 

     public void Clear() 
     { 
      MyItems.Clear(); 
     } 
    } 

내보기 :

<UserControl x:Class="CMDemo.Client.Views.MiscView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      mc:Ignorable="d" 
      d:DesignHeight="300" 
      d:DesignWidth="400"> 
    <StackPanel Orientation="Horizontal"> 
     <TextBlock Text="Test ComboBox" /> 
     <ComboBox x:Name="MyItems" 
        DisplayMemberPath="MyItemName" 
        Height="30" 
        VerticalAlignment="Top" /> 
     <Button x:Name="Load" 
       Height="30" 
       Content="Load" 
       VerticalAlignment="Top" /> 
     <Button x:Name="Clear" 
       Height="30" 
       Content="Clear" 
       VerticalAlignment="Top" /> 
     <TextBlock Text="Selected Item:" /> 
     <TextBlock x:Name="SelectedMyItem_MyItemName" /> 
    </StackPanel> 
</UserControl> 
관련 문제