我该如何初始化IList

Mas*_*ter 0 c# xaml

所以我的数据网格填充了一个Ilist

public IList SelectedItem2 { get; set; }
Run Code Online (Sandbox Code Playgroud)

我有一个双击动作,我想与索引零处选择的行值进行交互.

<telerik:RadGridView SelectedItem="{Binding SelectedItem2}" ItemsSource="{Binding AllQueries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="True">
    <telerik:RadGridView.RowStyle>
        <Style TargetType="telerik:GridViewRow">
              <Setter Property="cal:Message.Attach" Value="[Event MouseDoubleClick] = [Open2()]"/>
        </Style>
    </telerik:RadGridView.RowStyle>
</telerik:RadGridView>
Run Code Online (Sandbox Code Playgroud)

当我双击该行时会产生此错误.出错了Object reference not set to an instance of an object.

我想知道如何修复此错误,通常在ViewModel中我会做类似的事情

SelectedItem2 = new IList(); 
Run Code Online (Sandbox Code Playgroud)

但是没有这样的事情:s

在Open2中

 Interaction i;
 IRecord vm;
 using (var ctx = DB.Get()) i = ctx.Interactions.Find(SelectedItem2.IndexOf(0))
Run Code Online (Sandbox Code Playgroud)

ps2*_*oat 5

您无法初始化界面.您需要创建一个实现该接口的对象:

SelectedItem2 = new ArrayList(); 
Run Code Online (Sandbox Code Playgroud)

要么

SelectedItem2 = new List(of object);
Run Code Online (Sandbox Code Playgroud)

如果您的所有值都是相同的类型,我更喜欢使用类型:

IList(Of string) SelectedItem2;
SelectedItem2 = new List(of string);
Run Code Online (Sandbox Code Playgroud)