Attached property object is null?

5 posts, 0 answers
  1. Juzailie
    Juzailie avatar
    20 posts
    Member since:
    Apr 2013

    Posted 11 Jul 2014 Link to this post

    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?

  2. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 11 Jul 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Juzailie
    Juzailie avatar
    20 posts
    Member since:
    Apr 2013

    Posted 13 Jul 2014 Link to this post

    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 ?






  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 14 Jul 2014 Link to this post

    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.
     
  6. Juzailie
    Juzailie avatar
    20 posts
    Member since:
    Apr 2013

    Posted 14 Jul 2014 in reply to Kalin Link to this post

    Hi Kalin,
    InheritDataContext is help solving my issue, thanks for the guide :).
Back to Top
UI for WPF is Visual Studio 2017 Ready