List<Item> Items
사용자 지정 개체로 표시되는 ListBox
이 있습니다. Foreach 항목 사용자가 ComboBox
을 List<string> Options
으로 표시하고 선택한 Item이 Item의 속성으로 다시 연결되도록합니다. 목록 상자에서 개별 항목 속성을 바인딩하는 데 문제가 없지만 DataContext에 백업하여 옵션 목록을 가져 오는 방법은 무엇입니까?DataContext ComboBox ListBox 내부 바인딩
보기 모델은 내가 많은 추가 코드를 잘라 읽을 수있는 예에 도착하려고
<ListBox x:Name="ItemsListBox" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="50" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="ItemProperty1TB"
Text="{Binding Path=Property1, Mode=OneWay}"
Grid.Column="0"
/>
<ComboBox x:Name="OptionsCB"
SelectedItem ="{Binding ChosenOptions, Mode=TwoWay}"
ItemsSource="{Binding Path=DataContext.Options}"
Grid.Column="1"
PlaceholderText="Option"
/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
페이지의 DataContext에
class ViewModel
{
public ObservableCollection<string> Options { get; set; }
public ObservableCollection<Item> Items { get; set; }
}
XAML로 설정되고있다.
How to bind to a source inside a ListBox different from the ItemsSource already specified 이것은 존재하지 않는 AncestorType을 사용합니까?
ComboBox inside Listbox.ItemTemplate Binding problem 정적 리소스에 바인딩됩니다. 내 옵션을 정적 리소스에 넣어야합니까?
ElementName
유망 보이지만 내 IDE는 요소가 목록 상자 내부에 범위 권장합니다 ... 이 VISUAL STUDIO
을 신뢰하지 않는 난 그냥이 모든 잘못에 대해 건가?
뷰 모델은 속성이 아닌 필드를 가질 필요가있다. 그게 실제 코드인가요? –
실제 코드가 아니므로 그 부분을 빨리 바꿀 것입니다. – JaredStroeb
'ItemsSource = "{Binding Path = DataContext.Options, ElementName = ItemsListBox}"를 시도하십시오 " –