Mehrdad Kamelzadeh
Mehrdad Kamelzadeh

Reputation: 1784

Drag and Drop Reorder controls within Grid panel WPF

I am almost new to WPF.

I have a Grid panel shown in the picture. I want to add the drag & drop functionality so that a user can reorder the buttons within the cells of the grid (The user should be able to put the buttons into each cell she wants.)

<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="137*"/>
        <ColumnDefinition Width="139*"/>
        <ColumnDefinition Width="112*"/>
        <ColumnDefinition Width="129*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="58*"/>
        <RowDefinition Height="59*"/>
        <RowDefinition Height="60*"/>
        <RowDefinition Height="55*"/>
        <RowDefinition Height="88*"/>
    </Grid.RowDefinitions>

    <Button Content="Drag" Grid.Column="0" Grid.Row="0"></Button>
    <Button Content="Drag" Grid.Column="2" Grid.Row="0"></Button>
    <Button Content="Drag" Grid.Column="0" Grid.Row="3"></Button>
</Grid>

enter image description here

Upvotes: 4

Views: 3456

Answers (1)

wp78de
wp78de

Reputation: 18950

If you are looking for a reorderable GridView control in WPF, you will be disappointed. WPF does not have such a control; it does not even have a GridView. A possible solution would be to upgrade to a XAML based (Universal) app that allows you achieve your goal with ease, as demonstrated by the links in the comments, e.g. the Jerry Nixon example.

If you are not willing to roll your own and cannot ditch WPF your best bet is buy a UI component that allows you to do just that. There is Telerik UI for WPF, Infragistics, DevExpress, and others..

Upvotes: 1

Related Questions