使用caliburn micro进行组合框装订时出错

时间:2013-12-23 11:43:39

标签: c# wpf binding combobox caliburn.micro

嗨,我有这个组合框:

<ComboBox x:Name="Orders" Width="150" Grid.Row="0"
          HorizontalAlignment="Left"
          SelectedItem="{Binding Order}" Margin="3" />

这是viewmodel中的代码:

class MyFerViewModel : Screen, IMyFerViewModel
    {

        private string[] orders = { "ABC", "CDC", "EFR", "ACER" };

        private string order = "ABC";       

        public string[] Orders { get { return orders; } }

        public string Order
        {
            get { return order; }
            set
            {
                if (value != order)
                {
                    order = value;
                    Reorder();
                }
            }
        }

[..]

为什么当我看不到视图并在引导程序中出现此错误时?

  

“无法找到合同ABC的任何实例。”

1 个答案:

答案 0 :(得分:1)

您需要将ItemsSource绑定到组合框并进一步SelectedItem

<ComboBox x:Name="Orders" 
          Width="150" Grid.Row="0" 
          HorizontalAlignment="Left" 
          ItemsSource="{Binding Orders}"
          SelectedItem="{Binding Order}"          
          Margin="3" />

希望有所帮助......