我希望能夠訪問另一個ListBox
中的ListBox
的索引並增加該索引。我試圖使用ItemContainerGenerator
,但當我將該物品投放爲ListBox
或ItemsControl
時,它會返回null
。在WPF中如何增加另一個ListBox內的列表框的索引?
我想增加代碼後面的索引或viewmodel。
這裏是我的模板的基本結構
<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'? – 2014-11-14 18:58:16
我有一個列表框填充列表框我希望能夠遞增內部列表框的索引時,該列表框已被選中 – Bob 2014-11-14 19:00:41
您是否使用MVVM模式或代碼隱藏? – 2014-11-14 19:01:26