我似乎无法弄清楚为什么列表框项目彼此重叠......它们应该在彼此下方。这是一些标记和代码。
<ListBox x:Name="DeviceList" Background="#ff4c4c4c" BorderThickness="0" ScrollViewer.CanContentScroll="False" MouseEnter="DeviceList_MouseEnter" MouseLeave="DeviceList_MouseLeave"
ManipulationBoundaryFeedback="DeviceList_ManipulationBoundaryFeedback" ItemContainerStyle="{DynamicResource ResourceKey=ListBoxItemStyle}" PreviewMouseDown="DeviceList_PreviewMouseDown"
PreviewMouseMove="DeviceList_PreviewMouseMove" PreviewMouseUp="DeviceList_PreviewMouseUp" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DockPanel.Dock="Bottom">
<ListBox.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Utilities\Resources\Themes\Slider.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ListBox.Resources>
</ListBox>
#region Constructors
/// <summary>
/// Constructor.
/// </summary>
public ConfiguratorView()
{
InitializeComponent();
foreach (Device device in (Application.Current.Windows[1].DataContext as ConfiguratorViewModel).AvailableDevices)
{
devices.Add(AddDevice(device.Icon + "_def", device.Description));
}
DeviceList.ItemsSource = devices;
}
#endregion
#region Internal Members
/// <summary>
/// Add the device to the list of devices.
/// </summary>
/// <param name="icon"></param>
/// <param name="description"></param>
/// <returns></returns>
private Canvas AddDevice(string icon, string description)
{
Canvas canvas = new Canvas();
canvas.Name = icon;
ContentControl backgroundContent = new ContentControl();
Label label = new Label();
backgroundContent.Template = Application.Current.FindResource(icon) as ControlTemplate;
label.Content = description;
canvas.Children.Add(backgroundContent);
canvas.Children.Add(label);
return canvas;
}
设备列表将画布添加为项目...然后我将 ItemsSource 设置为列表。加载它会在最后一个图标的顶部显示所有图标。有什么想法吗?