0
我有一个列表框及其数据模板。但在它的DataTemplate中,我有CheckedCombobox DataTemplate。想知道如何设置绑定。我已经尝试了下面的东西,以获得哪些项目在每个列表框项目中检查子元素。下面是不工作的代码。在DataTemplate里面检查组合框是在列表框中DataTemplate
<ListBox
Name="ListLayers"
ItemsSource="{Binding LstDragList}"
Height="123"
Width="283"
SelectedIndex="{Binding SelectedRow, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<ComboBox
Name="childlayers"
Style="{StaticResource EditableCboStyle}"
ItemsSource="{Binding lstLayerModel}"
Text="{Binding SelectedLayers, UpdateSourceTrigger=PropertyChanged}"
ItemContainerStyle="{DynamicResource ComboboxItemContainerStyle}"
Width="200"
IsEditable="True"
IsReadOnly="False"
PreviewMouseLeftButtonDown="ComboBox_PreviewMouseLeftButtonDown"
>
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:Model}">
<CheckBox
VerticalAlignment="Center"
VerticalContentAlignment="Center"
IsChecked="{Binding IsChecked}"
Content="{Binding DisplayLayer}"
/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
型号:
public class DragList : ObservableObject
{
public DragList()
{
_selectedLayers = string.Empty;
}
public string FileName { get; set; }
public ObservableCollection<Model> lstLayerModel { get; set; }
public string Text { get; set; }
private string _selectedLayers;
public string SelectedLayers
{
get { return _selectedLayers; }
set { SetAndNotify(ref _selectedLayers, value,() => this.SelectedLayers); }
}
private int _selectedLayerInx;
public int SelectedLayerInx
{
get { return _selectedLayerInx; }
set { SetAndNotify(ref _selectedLayerInx, value,() => this.SelectedLayerInx); }
}
}
我的构造视图模型:
public ViewModel()
{
_lstLayers = new ObservableCollection<Model>();
mCheckedItems = new ObservableCollection<Model>();
_tempDragList = new List<DragList>();
_lstLayers.CollectionChanged += _lstLayers_CollectionChanged;
_lstLayers.Add(new Model
{
LayerName = "All",
LayerNumber = "",
IsChecked = true
});
_lstLayers.Add(new Model { LayerName = "Layer one", LayerNumber = "1", IsChecked = false });
_lstLayers.Add(new Model { LayerName = "Layer two", LayerNumber = "2", IsChecked = false });
_lstLayers.Add(new Model { LayerName = "Layer three", LayerNumber = "3", IsChecked = false });
_lstDragList = new List<DragList>();
_lstDragList.Add(new DragList { FileName = "Test", lstLayerModel = _lstLayers });
_lstDragList.Add(new DragList { FileName = "Test1", lstLayerModel = _lstLayers });
_tempDragList = _lstDragList;
}
你能解释一下哪些工作不正常吗? LstDragList实际上是viewmodel中公共属性的名称吗? –
模型是否有你想要绑定的属性? –
使用Snoop在运行时检查绑定(以及相关的DataContext)。 – Will