[英]Drag & Drop Tiles - WPF
I´d like to Drag Tiles from one NavigationBar to a Dashboard. 我想将Tiles从一个NavigationBar拖动到仪表板。 (Using Visual Studio 2015, C#, and WPF) Now I´m stuck to one question; (使用Visual Studio 2015,C#和WPF)现在我只想回答一个问题。 Which DataFormat has the Content of a Tile? 哪个DataFormat具有图块的内容? Only Image? 只有图片? But how do I use/cache it? 但是如何使用/缓存它?
private void tileFrom_MouseDown(object sender, MouseButtonEventArgs e)
{
Tile tileFrom = e.Source as Tile;
if (tileFrom!= null && e.LeftButton == MouseButtonState.Pressed)
{
DragDrop.DoDragDrop(tileFrom,
tileFrom.Content,
DragDropEffects.All);
}
}
private void tileTo_Drop(object sender, DragEventArgs e)
{
Tile tileTo = e.Source as Tile;
string draggedText = (string)e.Data.GetData(DataFormats.StringFormat);
tileTo.Content = draggedText;
}
Instead of the StringFormat
there must be some other way... Please help! 除了StringFormat
还必须有其他方法...请帮助!
in Drag and Drop, you can examine what formats are available using e.Data.GetFormats()
- I find it more useful to get the object and then check the type. 在拖放中,您可以使用e.Data.GetFormats()
检查可用的格式-我发现获取对象然后检查类型更为有用。
object data = e.Data.GetData(e.Data.GetFormats[0]);
var someTypeData = data as SomeType;
if(someTypeData != null) {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.