我在包装面板内部动态创建一个customcontrol。现在,我需要对包装面板中的自定义控件进行重新排序。是否可以通过拖放在包装面板内部重新排列自定义控件?
这是我的XAML代码
<DockPanel Grid.Column="1" Margin="208,40,1,94" Grid.Row="2"
Background="White" AllowDrop="True">
<ScrollViewer AllowDrop="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Width="443">
<StackPanel Width="443" >
<WrapPanel x:Name="pnl" HorizontalAlignment="Left"
Height="Auto"
VerticalAlignment="Top" Width="480" AllowDrop="True"
/>
</StackPanel>
</ScrollViewer>
</DockPanel>
我已经尝试将自动换行面板放在列表中,如给定答案(Ilan的答案)所建议的那样,现在我的面板在后面的代码中无法访问。我做错什么了吗?
参考方案
在这里,我演示了Buttons
,您可以根据需要对其进行修改。
Xaml
<WrapPanel x:Name="Pnl" Background="Yellow" Margin="0,0,0,128" Button.DragEnter="Button_DragEnter" Button.MouseRightButtonDown="Button_MouseDown">
<Button Content="Btn1" AllowDrop="True"/>
<Button Content="Btn2" AllowDrop="True"/>
<Button Content="Btn3" AllowDrop="True"/>
</WrapPanel>
码
Button btn_to_drag;
private void Button_MouseDown(object sender, MouseButtonEventArgs e)
{
btn_to_drag = (Button)e.Source;
DragDrop.DoDragDrop(btn_to_drag, btn_to_drag, DragDropEffects.Move);
}
private void Button_DragEnter(object sender, DragEventArgs e)
{
Button btn = (Button)e.Source;
int where_to_drop = Pnl.Children.IndexOf(btn);
Pnl.Children.Remove(btn_to_drag);
Pnl.Children.Insert(where_to_drop, btn_to_drag);
}
使用DataObject
的另一种方法消除了对btn_to_drag
声明的需要。
private void Button_MouseDown(object sender, MouseButtonEventArgs e)
{
DataObject data = new DataObject(DataFormats.Serializable, (Button)e.Source );
DragDrop.DoDragDrop((DependencyObject)e.Source, data, DragDropEffects.Move);
}
private void Button_DragEnter(object sender, DragEventArgs e)
{
Button btn_to_move = (Button) e.Data.GetData(DataFormats.Serializable);
int where_to_move = Pnl.Children.IndexOf((UIElement)e.Source);
int what_to_move = Pnl.Children.IndexOf(btn_to_move);
Pnl.Children.RemoveAt(what_to_move);
Pnl.Children.Insert(where_to_move, btn_to_move);
}
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
每个文件合并后添加换行 - python我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…
如何从php中获取datatables jQuery插件的json数据 - php我是PHP的新手,正在尝试使用Datatables jQuery插件。我知道我必须从.php文件中获取数据,然后在数据表中使用它,但是我似乎无法通过ajax将其传递给数据表。我设法从数据库中获取数据,并对其进行json编码,但是后来我不知道如何在我的index.php文件中调用它,并在其中显示它。我究竟做错了什么?这是我的代码:HTML(已编辑): <…
Json到php,json_decode返回NULL - php我正在用PHP进行JSON解析器的一些API,用于存储有关遗产的信息。我在解析时遇到问题,因为它返回的是NULL值而不是数组或对象。简单的JSON代码可以很好地解析,但是可以这样:{"success":true,"totalCount":1,"data":[{"id":99694…
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…