Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:43:17+00:00 2026-06-09T23:43:17+00:00

in my project i used wpf + prism.Inside a view,i must invoke a command

  • 0

in my project i used wpf + prism.Inside a view,i must invoke a command inside a context menu, the command is defined into the viewmodel class.this is the view:

<UserControl x:Class="GrigoLync.Modules.LyncClient.Contatti.ContattiView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:infr="clr-namespace:GrigoLync.infrastructure.Model.Lync;assembly=GrigoLync.infrastructure"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300" 

         >

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Label Grid.Column="0" Grid.Row="0" FontSize="12" Margin="5">Contatti</Label>

    <TreeView x:Name="groupTreeView" Margin="10" ItemsSource="{Binding GruppiLync}" >
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Path=ContattiLync}">
                <TextBlock Text="{Binding Path=Nome}" />
                <HierarchicalDataTemplate.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Uri}" Tag="{Binding}">
                        <TextBlock.ContextMenu>
                            <ContextMenu> 
                                <MenuItem Header ="Invia messaggio istantaneo" 
                                          Command="{Binding PlacementTarget.Tag.SendInstantMessageCommand,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, diag:PresentationTraceSources.TraceLevel=High}"/>                                         
                            </ContextMenu>
                        </TextBlock.ContextMenu>
                        </TextBlock>
                    </DataTemplate>
                </HierarchicalDataTemplate.ItemTemplate>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView> 

</Grid>

the following is the viewmodel class:

 [Export(typeof(ContattiViewModel))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class ContattiViewModel : NotificationObject
{

    private readonly ILyncClientService lyncClientService;
    private readonly IRegionManager regionManager;
    private readonly IEventAggregator eventAggregator;
    private List<GruppoLync> gruppiLync;
    private ICommand sendInstantMessageCommand;



     [ImportingConstructor]
    public ContattiViewModel(ILyncClientService lyncClientService, IRegionManager regionManager, IEventAggregator eventAggregator)
    {
        if (lyncClientService == null)
        {
            throw new ArgumentNullException("lyncClientService");
        }

        if (regionManager == null)
        {
            throw new ArgumentNullException("regionManager");
        }

        if (eventAggregator == null)
        {
            throw new ArgumentNullException("eventAggregator");
        }

        this.lyncClientService = lyncClientService;
        this.regionManager = regionManager;
        this.eventAggregator = eventAggregator;
        this.gruppiLync = lyncClientService.elencoGruppiLync();
        this.sendInstantMessageCommand = new DelegateCommand<object>(this.SendInstantMessage);

        //groupTreeView.DataItems = this.gruppiLync;

     }

     public ICommand SendInstantMessageCommand { get { return this.sendInstantMessageCommand; } }
     public List<GruppoLync> GruppiLync
     {
         get
         {
             return this.gruppiLync;
         }             
     }

     private void SendInstantMessage(object aContattoLync)
     {
         //This point is not executed!
     }



}

}

When i select from the user interface the menu item “Invia Messaggio istantaneo” the command is not invoke, This point is not executed
can help me please?!!!!
this is the GruppoLync class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace GrigoLync.infrastructure.Model.Lync
{
public class GruppoLync : INotifyPropertyChanged
{
    private string nome;
    public string Nome
    {
        get { return nome; }

        set { nome = value;
        OnPropertyChanged(new PropertyChangedEventArgs("Nome"));

        }
    }

    private ObservableCollection<ContattoLync> contattiLync;
    public ObservableCollection<ContattoLync> ContattiLync
    {
        get { return contattiLync; }
        set
        {
            contattiLync = value;
            OnPropertyChanged(new PropertyChangedEventArgs("ContattiLync"));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, e);
    }

    public GruppoLync(string nome, ObservableCollection<ContattoLync> contattiLync)
    {
        Nome = nome;
        ContattiLync = contattiLync;
    }
}

}

and this is ContattoLync class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;

namespace GrigoLync.infrastructure.Model.Lync
{
public class ContattoLync
{

    public string Uri { get; set; }
    public string Stato { get; set; }

}
}

I report also the trace log of the binding:

System.Windows.Data Warning: 54 : Created BindingExpression (hash=37997052) for Binding (hash=17879784)
System.Windows.Data Warning: 56 :   Path: 'PlacementTarget.Tag.SendInstantMessageCommand'
System.Windows.Data Warning: 58 : BindingExpression (hash=37997052): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=37997052): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=37997052): Attach to System.Windows.Controls.MenuItem.Command (hash=47163810)
System.Windows.Data Warning: 64 : BindingExpression (hash=37997052): RelativeSource (FindAncestor) requires tree context
System.Windows.Data Warning: 63 : BindingExpression (hash=37997052): Resolve source deferred
System.Windows.Data Warning: 54 : Created BindingExpression (hash=18607377) for Binding (hash=17879784)
System.Windows.Data Warning: 56 :   Path: 'PlacementTarget.Tag.SendInstantMessageCommand'
System.Windows.Data Warning: 58 : BindingExpression (hash=18607377): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=18607377): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=18607377): Attach to System.Windows.Controls.MenuItem.Command (hash=32025604)
System.Windows.Data Warning: 64 : BindingExpression (hash=18607377): RelativeSource (FindAncestor) requires tree context
System.Windows.Data Warning: 63 : BindingExpression (hash=18607377): Resolve source deferred
System.Windows.Data Warning: 65 : BindingExpression (hash=37997052): Resolving source 
System.Windows.Data Warning: 68 : BindingExpression (hash=37997052): Found data context element: <null> (OK)
System.Windows.Data Warning: 71 :     Lookup ancestor of type ContextMenu:  queried ContextMenu (hash=46231978)
System.Windows.Data Warning: 70 :   RelativeSource.FindAncestor found ContextMenu (hash=46231978)
System.Windows.Data Warning: 76 : BindingExpression (hash=37997052): Activate with root item ContextMenu (hash=46231978)
System.Windows.Data Warning: 106 : BindingExpression (hash=37997052):   At level 0 - for ContextMenu.PlacementTarget found accessor DependencyProperty(PlacementTarget)
System.Windows.Data Warning: 102 : BindingExpression (hash=37997052): Replace item at level 0 with ContextMenu (hash=46231978), using accessor DependencyProperty(PlacementTarget)
System.Windows.Data Warning: 99 : BindingExpression (hash=37997052): GetValue at level 0 from ContextMenu (hash=46231978) using DependencyProperty(PlacementTarget): <null>
System.Windows.Data Warning: 104 : BindingExpression (hash=37997052):   Item at level 1 is null - no accessor
System.Windows.Data Warning: 101 : BindingExpression (hash=37997052): Replace item at level 2 with {NullDataItem}
System.Windows.Data Warning: 78 : BindingExpression (hash=37997052): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=37997052): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 87 : BindingExpression (hash=37997052): TransferValue - using final value <null>
System.Windows.Data Warning: 65 : BindingExpression (hash=18607377): Resolving source 
System.Windows.Data Warning: 68 : BindingExpression (hash=18607377): Found data context element: <null> (OK)
System.Windows.Data Warning: 71 :     Lookup ancestor of type ContextMenu:  queried ContextMenu (hash=64235)
System.Windows.Data Warning: 70 :   RelativeSource.FindAncestor found ContextMenu (hash=64235)
System.Windows.Data Warning: 76 : BindingExpression (hash=18607377): Activate with root item ContextMenu (hash=64235)
System.Windows.Data Warning: 105 : BindingExpression (hash=18607377):   At level 0 using cached accessor for ContextMenu.PlacementTarget: DependencyProperty(PlacementTarget)
System.Windows.Data Warning: 102 : BindingExpression (hash=18607377): Replace item at level 0 with ContextMenu (hash=64235), using accessor DependencyProperty(PlacementTarget)
System.Windows.Data Warning: 99 : BindingExpression (hash=18607377): GetValue at level 0 from ContextMenu (hash=64235) using DependencyProperty(PlacementTarget): <null>
System.Windows.Data Warning: 104 : BindingExpression (hash=18607377):   Item at level 1 is null - no accessor
System.Windows.Data Warning: 101 : BindingExpression (hash=18607377): Replace item at level 2 with {NullDataItem}
System.Windows.Data Warning: 78 : BindingExpression (hash=18607377): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=18607377): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 87 : BindingExpression (hash=18607377): TransferValue - using final value <null>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:43:19+00:00Added an answer on June 9, 2026 at 11:43 pm

    I solve the problem!!!!

     <TreeView x:Name="groupTreeView" Margin="10" ItemsSource="{Binding GruppiLync}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Path=ContattiLync}">
                    <TextBlock Text="{Binding Path=Nome}" />
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Uri}" 
                                       Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}">
                            <TextBlock.ContextMenu>
                                <ContextMenu DataContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"> 
                                    <MenuItem Header ="Invia messaggio istantaneo" 
                                              Command="{Binding SendInstantMessageCommand, diag:PresentationTraceSources.TraceLevel=High}"
                                              CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                                </ContextMenu>
                            </TextBlock.ContextMenu>
                            </TextBlock>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView> 
    

    Thanks to All!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a ViewModel class like this in a Prism / WPF project. public class
I am using a base Window class in a WPF project. In the code
I have a WPF project with an AssemblyInfo.cs that groups multiple CLR namespaces into
I've used standard WPF Labels throughout my project. Now that I'm including the Telerik
I am working on a project using VS2010, WPF, and C#. I used SQL
I used Ribbon library for WPF for a big project. Now when I have
Project info: WPF, PRISM, C# 4.0, WCF, Entity framework, SQL(express) My database contains several
I have used data binding in my project in earlier version of WPF. I
I have a VS project used for my .NET WCF host with some simple
I have a Biztalk 2006 R2 project (used with ESB Guidance 1) I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.