【发布时间】:2017-07-09 16:50:48
【问题描述】:
我试图简单地定义第二个堆栈面板(根堆栈面板中的两个)的所有矩形元素的填充,所需的填充为白色。由于堆栈面板没有 ItemTemplate,我尝试将其替换为 ItemsControl,然后将其封装。当我看到 ItemsControl 没有 Orientation 属性时,堆栈面板的封装就出现了。
无论如何,子矩形仍然没有被白色填充...... >.
(我也在尝试对事件绑定做同样的事情,就像 How to set an event function via a style?天)
<Window x:Class="RegenboogDragDrop.WindowRegenboog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowRegenboog" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type Rectangle}">
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Width" Value="50"></Setter>
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="Stroke" Value="Black"></Setter>
<Setter Property="StrokeThickness" Value="3"></Setter>
</Style>
</Window.Resources>
<StackPanel>
<StackPanel Margin="0,50" Orientation="Horizontal" HorizontalAlignment="Center">
<Rectangle Fill="Yellow" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Orange" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Red" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Blue" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Green" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Violet" MouseMove="Rectangle_MouseMove"></Rectangle>
<Rectangle Fill="Indigo" MouseMove="Rectangle_MouseMove"></Rectangle>
</StackPanel>
<ItemsControl Name="DropZone" HorizontalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Rectangle Fill="White"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Name="dropRed" Fill="White"/>
<Rectangle Name="dropOrange" MouseMove="Rectangle_MouseMove" DragDrop.DragEnter="Rectangle_DragEnter" DragDrop.DragLeave="Rectangle_DragLeave" DragDrop.Drop="Rectangle_Drop" AllowDrop="True"></Rectangle>
<Rectangle Name="dropYellow" Fill="White" MouseMove="Rectangle_MouseMove" DragDrop.DragEnter="Rectangle_DragEnter" DragDrop.DragLeave="Rectangle_DragLeave" DragDrop.Drop="Rectangle_Drop" AllowDrop="True"></Rectangle>
<Rectangle Name="dropGreen"></Rectangle>
<Rectangle Name="dropBlue"></Rectangle>
<Rectangle Name="dropIndigo"></Rectangle>
<Rectangle Name="dropViolet"></Rectangle>
</StackPanel>
</ItemsControl>
<Button Name="ButtonCheck" Content="Check volgorde" Margin="5,50"></Button>
</StackPanel>
如果你想试试,后面的代码:(在第二行,第三个方块可以通过拖放接收颜色,而第二个有所有事件,但没有我需要的填充我正在努力让它拥有)(DutchVarsToEnglish:rechthoek 表示正方形,kleur 表示颜色,gesleepteKleur 表示 draggedColor,sleep 表示拖动):
https://defuse.ca/b/c19ncFwllWIpSRe6I0cclp(我不知道如何折叠 C# sn-p 就像这里的 js sn-p https://meta.stackexchange.com/questions/70885/collapse-code-snippets-in-answers :S 所以 pastebin 链接到代码隐藏)
【问题讨论】:
标签: c# wpf wpf-controls wpf-style