ListBoxItem的绑定

1、绑定父级的DataContext,需要添加DataContext头

{Binding DataContext.ChaterModel.ChatTarget.NrtModerator, RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType=ListBox}, Mode=OneWay}

2、获取前索引,要绑定到AlternationIndex(ListBox在ListBoxItem绑定),需要添加(ItemsControl.AlternationIndex)

{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorLevel=1, AncestorType=ListBoxItem}, Mode = Oneway}

Show Comments