This is a migrated thread and some comments may be shown as answers.

Disabling RowReorderBehavior?

2 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 01 Jul 2013, 11:27 PM
I'm trying to bring an app that was written against 2012.3.1017.40 forward, and I've run up against the dropping of RadDragAndDropManager.  So I'm trying to write our stuff to use the new DragDropManager. And I'm having a problem.

We have a grid on which we want drag-and-drop reordering only sometimes.  So I've bound RowReorderBehavior.IsEnabled to a property on my viewmodel.  And here's the odd thing - it only works to turn RowReorderBehavior on, not off.

I can trace, in the debugger, the property as its value is set, and I can see it raising INotifyPropertyChanged. And if I'm setting it to true, I then trace through RowReorderBehavior.OnIsEnabledPropertyChanged(). But if I set it to false, I'm still raising INotifyPropertyChanged, but RowReorderBehavior.OnIsEnabledPropertyChanged() is never called.

I can replicate this in the Q3 2012 Row Reorder demo.

To RowReorderBehavior.cs, I add the following class:
public class SortingAllowed : INotifyPropertyChanged
{
    public SortingAllowed()
    {
        this.allowSorting = false;
    }
 
    private bool allowSorting_;
    public bool allowSorting
    {
        get { return this.allowSorting_; }
        set
        {
            this.allowSorting_ = value;
            OnPropertyChanged("allowSorting");
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

Then in Example.xaml, I add a static instance to Grid.Resources, create a couple of row definitions, set a checkbox in row 0, move the RadGridView to row 1, then bind Checkbox.IsChecked and RadGridView's RowReorderBehavior.IsEnabled to the static resource:
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.Resources>
        <local:SortingAllowed x:Key="sortingAllowed" />
 
        <Style TargetType="telerik:GridViewRow"
               x:Key="DraggedRowStyle"
               BasedOn="{StaticResource GridViewRowStyle}">
            <Setter Property="telerik:DragDropManager.AllowDrag"
                    Value="True" />
        </Style>
    </Grid.Resources>
    <StackPanel Grid.Row="0" Orientation="Horizontal">
        <CheckBox IsChecked="{Binding Source={StaticResource sortingAllowed}, Path=allowSorting}">Allow sorting</CheckBox>
    </StackPanel>
    <telerik:RadGridView
                         Grid.Row="1"
                         x:Name="RadGridView1" GroupRenderMode="Flat"
                         ShowGroupPanel="False" CanUserResizeRows="True"
                         ItemsSource="{Binding Customers}"
                         RowStyle="{StaticResource DraggedRowStyle}"
                         AllowDrop="True"
                         CanUserSortColumns="False"
                         local:RowReorderBehavior.IsEnabled="{Binding Source={StaticResource sortingAllowed}, Path=allowSorting}"
                         telerik:ScrollingSettingsBehavior.IsEnabled="True"
                         telerik:ScrollingSettingsBehavior.ScrollAreaPadding="30"
                         telerik:ScrollingSettingsBehavior.ScrollStep="24"
                         telerik:ScrollingSettingsBehavior.ScrollStepTime="00:00:00.05">

2 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 04 Jul 2013, 11:37 AM
Hello Jeffrey,

The property changed callback of the IsEnabled dependency property will be called only if there is a change in the value. If you are initially setting it to false, the callback will not be called until you set it to true. 

Is this happening if you change the property at runtime? 

Regards,
Nik
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jeff
Top achievements
Rank 1
answered on 11 Jul 2013, 02:41 PM

It looks like the IsEnabled property that I’m creating is shadowing another IsEnabled that exists elsewhere in the framework.

When I use a property with a different name, I see the OnPropertyChanged method called, whichever way I set it. (And I still see an IsEnabled property in the IntelliSense tooltips, even though I no longer have one in my code).

In any case, using a different property name solves my issue - but it's an odd behavior, and I wish I understood better what is going on.

Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or