Hi,
I am generating a set of labels from codebehind in wpf, C#. I can drag and drop the last label only once. I am not able to drag and drop any other labels.
The C# code is as follows:
ImgFloorPlan.Source = new BitmapImage(new Uri(rootDic + "\\" + filename));
.
.
.
.
foreach (string room in roomsList)
{
lbl = new Label();
lbl.Content = room;
lbl.Foreground = Brushes.White;
lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
lbl.Background = Brushes.Gray;
lbl.Margin = new Thickness { Left = 5, Top = j };
lbl.MouseDown += new MouseButtonEventHandler(StkRooms_MouseDown);
lbl.MouseMove += new MouseEventHandler(StkRooms_MouseMove);
lbl.Cursor = Cursors.Hand;
lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
CnvsFloorPlan.Children.Add(lbl);
i++;
j += 30;
}
All the above labels are added to a canvas. ImgFloorPlan is also added to the canvas. All the above labels should be dragged and dropped over the image.
XAML code is as follows:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="26,63,98,185" x:Name="_scrollViewer">
<Canvas x:Name="CnvsFloorPlan">
<Grid x:Name="GrdFloorPlan" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{Binding ElementName=CnvsFloorPlan, Path=ActualWidth}" Height="{Binding ElementName=CnvsFloorPlan, Path=ActualHeight}" >
<Image x:Name="ImgFloorPlan" Source="Images/blank.png" HorizontalAlignment="left" VerticalAlignment="Top" AllowDrop="True" Drop="ImgFloorPlan_Drop" Visibility="Visible" />
</Grid>
</Canvas>
</ScrollViewer>
Can anyone help me with this please? I have spent more than 3 weeks trying to fix this. I just have to populate multiple labels depending on the condition. and user should be able to drag and drop these labels over the image. Please help me with this.
Thanks in advance