简体   繁体   English

画布位置(x,y)

[英]Canvas Position (x,y)

I have an ItemsControl that has a collection source, the items appear in canvas and I can move them with mouse events, How I can save position of an Item (x,y)? 我有一个具有收集源的ItemsControl,这些项目显示在画布中,并且可以通过鼠标事件移动它们,如何保存项目(x,y)的位置?

This is my code : 这是我的代码:

 <ItemsControl x:Name="icTables" Padding="0,30,0,0" Margin="249,88,0,115" Width="737" HorizontalAlignment="Left" FontWeight="Bold" BorderBrush="#FF6C6C6C" BorderThickness="1">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <jas:DragCanvas x:Name="drCanvas"></jas:DragCanvas>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ToggleButton x:Name="btnTable" Foreground="#ff252526" Width="75" Height="75">
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="{Binding TableNo}" FontSize="14" HorizontalAlignment="Center" Foreground="#FFECECEC"/>
                    </StackPanel>
                </ToggleButton>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

Thanks. 谢谢。

您可以为Canvas中的所有项目指定每个项目,检索它们的Left和Top值并存储它们,也可以在Item ViewModels中的Canvas.Left和Canvas.Top属性和2个匹配属性之间进行TwoWay数据绑定,并在其中存储值。

probably you should extend DragCanvas, when drag done event raised, you should save the position info to item(via attached dependency property). 可能您应该扩展DragCanvas,当发生拖动完成事件时,应该将位置信息保存到item(通过附加的依赖项属性)。

drCanvas.DragCompleted +=(s,e)=>
{
   var pos = Mouse.GetPosition(this);
   ToggleButton.SetValue(PositionAttachedDependencyProperty,pos);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM