Click here to Skip to main content
15,914,642 members
Home / Discussions / WPF
   

WPF

 
QuestionTrouble setting cooperative level [SharpDX] Pin
Jayme6523-Jan-15 6:00
Jayme6523-Jan-15 6:00 
QuestionCode only working with break points Pin
Dominick Marciano9-Jan-15 19:14
professionalDominick Marciano9-Jan-15 19:14 
AnswerRe: Code only working with break points Pin
SledgeHammer019-Jan-15 19:15
SledgeHammer019-Jan-15 19:15 
AnswerRe: Code only working with break points Pin
Afzaal Ahmad Zeeshan9-Jan-15 20:29
professionalAfzaal Ahmad Zeeshan9-Jan-15 20:29 
QuestionAnybody using DwmExtendFrameIntoClientArea? Pin
SledgeHammer019-Jan-15 11:59
SledgeHammer019-Jan-15 11:59 
AnswerRe: Anybody using DwmExtendFrameIntoClientArea? Pin
Richard Deeming12-Jan-15 2:31
mveRichard Deeming12-Jan-15 2:31 
GeneralRe: Anybody using DwmExtendFrameIntoClientArea? Pin
SledgeHammer0112-Jan-15 4:52
SledgeHammer0112-Jan-15 4:52 
QuestionWhere to go to learn wpf? Pin
MrGlass35-Jan-15 8:44
MrGlass35-Jan-15 8:44 
AnswerRe: Where to go to learn wpf? Pin
SledgeHammer015-Jan-15 9:59
SledgeHammer015-Jan-15 9:59 
AnswerRe: Where to go to learn wpf? Pin
Mycroft Holmes5-Jan-15 12:11
professionalMycroft Holmes5-Jan-15 12:11 
GeneralRe: Where to go to learn wpf? Pin
SledgeHammer015-Jan-15 12:58
SledgeHammer015-Jan-15 12:58 
GeneralRe: Where to go to learn wpf? Pin
Mycroft Holmes5-Jan-15 13:21
professionalMycroft Holmes5-Jan-15 13:21 
AnswerRe: Where to go to learn wpf? Pin
Richard MacCutchan5-Jan-15 22:43
mveRichard MacCutchan5-Jan-15 22:43 
AnswerRe: Where to go to learn wpf? Pin
Vimalsoft(Pty) Ltd12-Jan-15 20:56
professionalVimalsoft(Pty) Ltd12-Jan-15 20:56 
AnswerRe: Where to go to learn wpf? Pin
Subramanyam Shankar17-Mar-15 1:04
professionalSubramanyam Shankar17-Mar-15 1:04 
QuestionMultithreaded Windows with Data Binding Pin
Dominick Marciano5-Jan-15 8:30
professionalDominick Marciano5-Jan-15 8:30 
AnswerRe: Multithreaded Windows with Data Binding Pin
Afzaal Ahmad Zeeshan9-Jan-15 8:41
professionalAfzaal Ahmad Zeeshan9-Jan-15 8:41 
AnswerRe: Multithreaded Windows with Data Binding Pin
SledgeHammer0111-Jan-15 8:37
SledgeHammer0111-Jan-15 8:37 
QuestionWPF DataGrid with ComBox Bound To Enums - Show Descriptions Pin
Kevin Marois5-Jan-15 7:03
professionalKevin Marois5-Jan-15 7:03 
AnswerRe: WPF DataGrid with ComBox Bound To Enums - Show Descriptions Pin
Pete O'Hanlon5-Jan-15 7:19
mvePete O'Hanlon5-Jan-15 7:19 
QuestionGetting error when i drag&drop in WPF Pin
VisualLive1-Jan-15 17:35
VisualLive1-Jan-15 17:35 
Hello,
i am developing a Form where the user need to drag and drop between Grid,StackPanel etc. some data you can see the code below :
<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Grid x:Name="box1" Grid.Row="0" AllowDrop="True" Drop="box_Drop" >
        <Grid x:Name="grid1" Background="Aqua" Margin="15" MouseMove="grid_MouseMove">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="28*" />
                <ColumnDefinition Width="445*" />
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0" Grid.Row="0">
                <TextBlock Text="1"></TextBlock>
            </Grid>
            <Grid Grid.Column="0" Grid.Row="1">
                <TextBlock Text="2"></TextBlock>
            </Grid>
            <Grid Grid.Column="0" Grid.Row="2">
                <TextBlock Text="3"></TextBlock>
            </Grid>
            <StackPanel Name="firsts" AllowDrop="True" Drop="box_Drop_first" Grid.Row="0" Grid.Column="1"  >

                <StackPanel MouseMove="grid_MouseMove_first" Name="firstsrow"  Margin="2" Background="Beige" Height="17"></StackPanel>
                </StackPanel>
            <StackPanel Name="seconds" AllowDrop="True" Grid.Row="1" Grid.Column="1" Drop="box_Drop_first"  >
                <StackPanel MouseMove="grid_MouseMove_first" Name="secondrow"  Margin="2" Background="Gainsboro" Height="17"></StackPanel>
                </StackPanel>
            <StackPanel Name="thirds" AllowDrop="True" Grid.Row="2" Grid.Column="1" Drop="box_Drop_first" >
                <StackPanel MouseMove="grid_MouseMove_first"  Name="thirdrow"  Margin="2" Background="Red" Height="17"></StackPanel>
                </StackPanel>
        </Grid>
    </Grid>
    <Grid x:Name="box2" Grid.Row="1" AllowDrop="True" Drop="box_Drop">
        <Grid x:Name="grid2" Background="blue" Margin="15" MouseMove="grid_MouseMove">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="28*" />
                <ColumnDefinition Width="445*" />
            </Grid.ColumnDefinitions>
        </Grid>
    </Grid>
    <Grid x:Name="box3" Grid.Row="2" AllowDrop="True" Drop="box_Drop">
        <TextBlock  Text="3" HorizontalAlignment="Left" Width="30" Margin="10,0,0,77"></TextBlock>
        <Grid x:Name="grid3" Background="green" Margin="15" MouseMove="grid_MouseMove">
        </Grid>

    </Grid>

</Grid>


and the code Behind :
public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
      }


      private void grid_MouseMove(object sender, MouseEventArgs e)
      {
          // Get the grid that is the source of drag
          Grid selectedGrid = sender as Grid;

          if (selectedGrid != null && e.LeftButton == MouseButtonState.Pressed)
          {
              // Add that grid as drag source and data
              DragDrop.DoDragDrop(selectedGrid, selectedGrid, DragDropEffects.Move);
          }
      }

      private void box_Drop(object sender, DragEventArgs e)
      {
          // Get the selected box in which the object is being dropped
          Grid selectedBox = sender as Grid;

          if (selectedBox != null)
          {
              // Get that data that is being dropped - in this case, the grid from other box
              Grid droppedGrid = (Grid)e.Data.GetData(typeof(Grid));

              // We need to remove the dragged grid from it's source box in order to be able to add it to selected box
              Grid sourceBox = (Grid)droppedGrid.Parent;
              // Remove the dropped grid from source box
              sourceBox.Children.Remove(droppedGrid);

              // We need to remove the other grid from the selected box in order to be able to move it to source box
              // Get existing child element, the box has only one child - the grid that we need
              Grid existingChild = (Grid)selectedBox.Children[0];
              // Remove existing child grid from selected box
              selectedBox.Children.Remove(existingChild);

              // Finally, move grids to new boxes
              // Move existing child grid to source box
              sourceBox.Children.Add(existingChild);
              // Move the dropped grid to selected box
              selectedBox.Children.Add(droppedGrid);
          }
      }


      private void box_Drop_first(object sender, DragEventArgs e)
      {
          StackPanel selectedBox = sender as StackPanel;

          if (selectedBox != null)
          {
              // Get that data that is being dropped - in this case, the grid from other box
              StackPanel droppedGrid = (StackPanel)e.Data.GetData(typeof(StackPanel));

              // We need to remove the dragged grid from it's source box in order to be able to add it to selected box
            //  StackPanel sourceBox = new StackPanel();
            StackPanel  sourceBox = (StackPanel)droppedGrid.Parent;
              // Remove the dropped grid from source box
              sourceBox.Children.Remove(droppedGrid);

              // We need to remove the other grid from the selected box in order to be able to move it to source box
              // Get existing child element, the box has only one child - the grid that we need
              StackPanel existingChild = (StackPanel)selectedBox.Children[0];
              // Remove existing child grid from selected box
              selectedBox.Children.Remove(existingChild);

              // Finally, move grids to new boxes
              // Move existing child grid to source box
              sourceBox.Children.Add(existingChild);
              // Move the dropped grid to selected box
              selectedBox.Children.Add(droppedGrid);
          }
      }

      private void grid_MouseMove_first(object sender, MouseEventArgs e)
      {
          StackPanel selectedGrid = sender as StackPanel;

          if (selectedGrid != null && e.LeftButton == MouseButtonState.Pressed)
          {
              // Add that grid as drag source and data
              DragDrop.DoDragDrop(selectedGrid, selectedGrid, DragDropEffects.Move);
          }
      }
  }


The Grids "box1,box2,box3" are not movable instead their Childs are all movable (beacause in teh final project these will be populate with data then the user should be able to move and change the data when need) .
When i debug the project and i want move the StackPanel"firstrow,secondrow,thirdrow" between others StackPanel as"firsts,seconds.thirds" i got always an error as "Object reference not set to an instance of an object." or "Specified argument was out of the range of valid values.
Parameter name: index
" then don't allow to drag drop .
Sincerely i am new of WPF then sure i done some mistakes then i ask you kindly if you have some suggestion or better idea to work out this error.

Thank you in advance for the attention.

Sincerely
AnswerRe: Getting error when i drag&drop in WPF Pin
Afzaal Ahmad Zeeshan9-Jan-15 8:44
professionalAfzaal Ahmad Zeeshan9-Jan-15 8:44 
AnswerRe: Getting error when i drag&drop in WPF Pin
Vimalsoft(Pty) Ltd11-Jan-15 23:52
professionalVimalsoft(Pty) Ltd11-Jan-15 23:52 
QuestionLoop in Dispatch.Invoke Not Updating UI Pin
Dominick Marciano31-Dec-14 16:15
professionalDominick Marciano31-Dec-14 16:15 
QuestionSelectionChanged Event is not firing on View Load in MVVM Pin
Ashfaque Hussain29-Dec-14 20:15
Ashfaque Hussain29-Dec-14 20:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.