我有ListBox
,其中包含一些项目。我想实现:
1)按CTRL键选择不同的项目。
2)用于更改项目的Tab键。
3)Shift +标签控件..
我正在使用SelectionMode=Extended
,但是CTRL不起作用,为什么?
当我按Tab键时,它只会切换第一项,为什么?
的Xaml:
<Window.Resources>
<Style x:Key="ButtonStyle2" TargetType="{x:Type CheckBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Canvas>
<Path x:Name="path" Data="{Binding PathCoords}" Margin="{Binding Margin}" Fill="#FFF4F4F5" Stretch="Fill" Stroke="Black"/>
</Canvas>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Stroke" TargetName="path" Value="#FFCF2222"/>
<Setter Property="StrokeThickness" TargetName="path" Value="2"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Items}" SelectionMode="Extended">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas></Canvas>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Style="{DynamicResource ButtonStyle2}" Focusable="True"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
代码:
namespace WpfApplication13
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new Data();
InitializeComponent();
}
}
public class Element
{
public string PathCoords { get; set; }
public string Margin { get; set; }
public int id { get; set; }
}
public class Data
{
public List<Element> Items { get; set; }
public Data()
{
Items = new List<Element>();
Items.Add(new Element { PathCoords = "M52,92L89.5,57.5 99.5,100.5z" });
Items.Add(new Element { PathCoords = "M131,104L150.5,39.5 204.5,87.5 155.5,88.5z" ,Margin="131,39.5,0,0"});
Items.Add(new Element { PathCoords = "M232,105L231.5,49.5 294.5,49.5 291.5,97.5z", Margin = "231.5,49.5,0,0" });
Items.Add(new Element { PathCoords = "M75,183L85.5,154.5 107.5,185.5z", Margin = "75,154.5,0,0" });
Items.Add(new Element { PathCoords = "M167,222L166.5,169.5 230.5,190.5z", Margin = "166.5,169.5,0,0" });
Items.Add(new Element { PathCoords = "M258,199L273.5,146.5 332.5,161.5 327.5,207.5z", Margin = "258,146.5,0,0" });
}
}
}