ListBox
의 인덱스에 액세스하여 해당 인덱스를 증가시키고 싶습니다. ItemContainerGenerator
을 사용하려고했지만 ListBox
또는 ItemsControl
으로 항목을 캐스팅 할 때 null
을 반환합니다.WPF에서 다른 ListBox 내부에서 ListBox의 인덱스를 어떻게 증가시킬 수 있습니까?
코드 또는 뷰 모델에서 색인을 증가시키고 싶습니다. 여기
내 템플릿의 기본 구조입니다<Window x:Class="WpfApplication12.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="MyListStyle" TargetType="{x:Type ListBox}">
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="SelectedIndex" Value="0"></Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal">
</VirtualizingStackPanel>
</ItemsPanelTemplate >
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="Visibility" Value="Collapsed"></Setter>
<!--<Setter Property="Margin" Value="2" />-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ListBox Name="InnerList" ItemsSource="{Binding}" ></ListBox>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Visibility" Value="Visible"/>
</Trigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="1" Click="Button_Click">button</Button>
<ListBox Style="{StaticResource MyListStyle}" Name="ListItemsControl" VirtualizingPanel.IsVirtualizing="True" Grid.Row="0"></ListBox>
</Grid>
</Window>
Here is some code to load the list
public MainWindow()
{
InitializeComponent();
CompositeCollection cc = new CompositeCollection();
cc.Add(new List<int>() { 1, 2, 3, 4, 5 });
cc.Add(new List<int>() { 6, 7, 8, 9, 10 });
cc.Add(new List<int>() { 11, 12, 13, 14, 15 });
ListItemsControl.ItemsSource = cc;
}
내부 'ListBox'는 실제로 다른 'ListBox'안에 있거나 단순히 다른 ListBox의 선택된 인덱스를 기반으로 하나의 'ListBox'를 증가 시키시겠습니까? –
목록 상자로 채워진 목록 상자 목록 상자가 선택되었을 때 내부 목록 상자의 색인을 증가시킬 수 있기를 원합니다. – Bob
MVVM 패턴 또는 코드 숨김을 사용하고 있습니까? –