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

Attached property object is null?

4 Answers 173 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Juzailie
Top achievements
Rank 2
Juzailie asked on 11 Jul 2014, 07:51 AM
hello there,
I want to get Commmand Object pass into the custom attached property with this control but then there is no result, but when I used the built in .net ContextMenu is okay, I'm trying to get this done in MVVM way is there any suggestion or ideas?

4 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 11 Jul 2014, 10:27 AM
Hello Juzailie,

I tested the described scenario and the bound command was successfully executed. For your convenience I have attached my test project so you can check it and let me know if I have missed anything here.

Hope this will help you.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Juzailie
Top achievements
Rank 2
answered on 14 Jul 2014, 03:33 AM
HI Kalin,
I see the issue from my side, after comparing with your codes, mine is I put the ContextMenu inside GridView then the DataContext assigned trough ContextMenu control name

example :
myContextMenuName.DataContext = new MyViewModel();

I've also tried  to set this DataContext trough xaml also the same,

<telerik:RadContextMenu.ContextMenu> 
        <telerik:RadContextMenu x:Name="GridContextMenu" 
                                ItemContainerStyle="{StaticResource MenuItemContainerStyle}"
                                local:CasesContextMenuBehaviour.ContextMenuOpenedCommand="{Binding OpenedCommand}">
            <telerik:RadContextMenu.DataContext>
                <local:CasesContextMenuViewModel/>
            </telerik:RadContextMenu.DataContext>
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>

from here what I encounter is DataContext of this ContextMenu can't be assign like so, the only way I've tried with success is by assigning the ViewModel to window or usercontrol level then it's there. Why we need to put RadContextMenu outer panel since I only want to display this ContextMenu on specific element and assigning DataContext of the ContextMenu trough it's control name can't ?






0
Kalin
Telerik team
answered on 14 Jul 2014, 01:14 PM
Hi Juzailie,

By default the ContextMenu inherits the DataContext from the element on which is attached on. If you need to set its DataContext manually you would need to set its InheritDataContext property to false. Please test it and let me know if does it help.

Hope it will work for you.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Juzailie
Top achievements
Rank 2
answered on 15 Jul 2014, 01:29 AM
Hi Kalin,
InheritDataContext is help solving my issue, thanks for the guide :).
Tags
ContextMenu
Asked by
Juzailie
Top achievements
Rank 2
Answers by
Kalin
Telerik team
Juzailie
Top achievements
Rank 2
Share this question
or