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

AssociatedObject object is always null for gridViewColumn

4 Answers 445 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ken
Top achievements
Rank 1
ken asked on 04 Apr 2011, 09:22 PM
Hi there, I am trying to create a behavior I can use to set the width of certain columns to 0 if certain things happen but when I try to access the AssociatedObject it is always null. I think the code will better explain this...

public static readonly DependencyProperty VisibilityProperty =
        DependencyProperty.Register("Visibility", typeof(bool), typeof(HideRadGridViewColumnBehavior),
        new PropertyMetadata(OnVisibilityPropertyChanged));
 
private static void OnVisibilityPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
{
  if (((HideRadGridViewColumnBehavior)target).AssociatedObject == null)
  {
    MessageBox.Show("AssociatedObject is null");
  }
  else
  {
    var col = ((HideRadGridViewColumnBehavior)target).AssociatedObject as GridViewDataColumn;
    col.Width = 0;
    col.Header = "";
    col.IsResizable = false;
  }
}

It's fairly obvious what I want to do there however no matter what the AssociatedObject is null, Here is the XAML I am using - hopefully someone can point me in the right direction on this.

<telerik:GridViewDataColumn DataMemberBinding="{Binding ModelId}"  Header="ID">
  <i:Interaction.Behaviors>
    <b:HideRadGridViewColumnBehavior Visibility="{Binding Path=DevMode}"/>
  </i:Interaction.Behaviors>
</telerik:GridViewDataColumn>

Thanks alot!!!

4 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 07 Apr 2011, 05:47 PM
Hi ken,

I tried compiling a sample project, using your code snippets, but I couldn't actually make it really work. Could you please have a look at it and inform me if there are any differences between your approach and mine.

Best wishes,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ivan Ivanov
Telerik team
answered on 07 Apr 2011, 06:07 PM
Hello ken,

Please excuse me, I have sent you a wrong project in my previous post.

All the best,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ken
Top achievements
Rank 1
answered on 07 Apr 2011, 09:41 PM
Opps - I don't have the Silverlight SDK. This is for a WPF desktop app.
0
Ivan Ivanov
Telerik team
answered on 12 Apr 2011, 03:16 PM
Hi ken,

RadGridView's columns are not visual objects, so they are not added to the visual tree. Please check this example: Examples > RadGridView > GroupByFormattedValue and inform us if the used approach meets your requirements. Do not hesitate to contact us if you have any further inquiries.

Greetings,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
ken
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
ken
Top achievements
Rank 1
Share this question
or