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 6746151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:17:21+00:00 2026-05-26T12:17:21+00:00

I have a little problem with MVVM. Let me first sketch my problem. I

  • 0

I have a little problem with MVVM. Let me first sketch my problem.

I have a Parent View (DashboardConsultants) which has a datagrid. Each cell in that DataGrid has a tooltip, implemented like this:

 <UserControl.Resources>
        <ResourceDictionary>
            <DataTemplate DataType="{x:Type vm:UC1001_AgreementDetailsViewModel}">
                <v:UC1001_AgreementDetails_View />
            </DataTemplate>    
        </ResourceDictionary>
 </UserControl.Resources>

<DataGridTextColumn.ElementStyle>
      <Style TargetType="{x:Type TextBlock}">
      <Setter Property="DataGridCell.ToolTip">
              <Setter.Value>
                   <vm:UC1001_AgreementDetailsViewModel />
              </Setter.Value>
      </Setter>

The tooltip calls up my ViewModel (AgreementDetailsViewModel), which has the following code:

public UC1001_ActiveAgreementContract AgreementDetailsContract { get; set; }

public int AgreementID { get; set; }

public UC1001_AgreementDetailsViewModel()
{
    AgreementDetailsContract = new UC1001_ActiveAgreementContract();
    this.Initialize();
}

private void Initialize()
{
    GetRefData();
    ShowAgreementDetailsView();
}

private void GetRefData()
{
    UC1001_ActiveAgreementArguments args = new UC1001_ActiveAgreementArguments();
    args.AgreementID = 3;
    DefaultCacheProvider defaultCacheProvider = new DefaultCacheProvider();
    if (!defaultCacheProvider.IsSet("AgrDet:" + args.AgreementID))
    {
        ConsultantServiceClient client = new ConsultantServiceClient();

        AgreementDetailsContract = client.GetAgreementDetailsByAgreementID(args);
        defaultCacheProvider.Set("AgrDet:" + args.AgreementID, AgreementDetailsContract, 5);
    }
    else
    {
        AgreementDetailsContract = (UC1001_ActiveAgreementContract)defaultCacheProvider.Get("AgrDet:" + args.AgreementID);
    }
}


private void ShowAgreementDetailsView()
{
    // Initialize
    var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

    // Show content
    var agreementDetailsWorkspace = new Uri("UC1001_AgreementDetails_View", UriKind.Relative);
    regionManager.RequestNavigate("ContentRegion", agreementDetailsWorkspace);
}

The goal of the ViewModel is to get an Agreement from the database (currently a static one…) and then pass it on to the child View (UC1001_AgreementDetails_View) to show as the tooltip. The child View has the following constructor so the controls can bind to the contract:

public UC1001_AgreementDetails_View(ViewModels.UC1001_AgreementDetailsViewModel UC1001_AgreementDetailsViewModel)
    {            
        InitializeComponent();
        this.DataContext = UC1001_AgreementDetailsViewModel.AgreementDetailsContract;
    }

I put a breakpoint on the ViewModel Initialize, and it fires when I get on the parent View, but it should fire when I get on the child View (thus when opening the tooltip in the datagrid). Does anyone know how I can fix this?

More information/code can be provided if needed.

EDIT:

I tried some stuff and I now I got something like this (which I feel is a little closer to the solution).

I changed my tooltip to the following (according to Rachels help):

<Setter Property="DataGridCell.ToolTip">
          <Setter.Value>
                <v:UC1001_AgreementDetails_View DataContext="{Binding AgreementDetailsViewModel}" />
          </Setter.Value>
</Setter>

In my child view, I put the following binding

<Label Content="{Binding AgreementDetailsContract.Header}" Height="50" HorizontalAlignment="Left" Margin="8,6,0,0" Name="_labelHoofding" VerticalAlignment="Top" FontSize="22" />

Now my AgreementDetailsViewModel, which has a property called AgreementDetailsContract with all the information I want to show, is the DataContext of my child view. But my problem still exist. The AgreementDetailsViewModels fires on opening the ConsultantDashboard, when it should open on displaying the tooltip. Is there some kind of event/command I can put on the tooltip to fire the ViewModel? Also, I think something is wrong with the Binding of my label because it doesn’t show information (altough it could be the same problem that the ViewModel doesn’t pass the right information).

Again, if it looks a little complex to you, I will be happy to explain it further, or give more code if asked.

SOLVED:

I got the solution. I specify the binding in the constructor of the ChildView instead of its XAML or in the View Tooltip.

public UC1001_AgreementDetails_View()
   {
      InitializeComponent();
      this.DataContext = new UC1001_AgreementDetailsViewModel();
   } 
  • 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-05-26T12:17:22+00:00Added an answer on May 26, 2026 at 12:17 pm

    It looks like your View is directly referencing the ViewModel, which means it will create a copy of your ViewModel when it starts up

    This code

    <Setter Property="DataGridCell.ToolTip">
        <Setter.Value>
            <vm:UC1001_AgreementDetailsViewModel />
        </Setter.Value>
    </Setter>
    

    Should be

    <Setter Property="DataGridCell.ToolTip">
        <Setter.Value>
            <!-- If you want to keep the DataTemplate, use a ContentControl -->
            <v:UC1001_AgreementDetails_View DataContext="{Binding AgreementDetails}" />
        </Setter.Value>
    </Setter>
    

    Your Data Structure should look something like this:

    class MainViewModel
    {
        ObservableCollection<AgreementViewModel> Agreements;
    }
    
    class AgreementViewModel
    { 
        // Loaded only when getter is called
        AgreementDetailViewModel AgreementDetails;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with a FileReference which I use to let users
I have a little problem with a simple vbScript. The script has to run
I have this little problem, that I cannot figure out which arguments to pass
i have little problem how i will recognize which item was clicked with OnClickEvent.
I have a little problem. My friend has a database with over 10 tables
have a little problem with this code: UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
Hey most of my issue has been solved but i have little problem This
i have little problem with boost::asio library. My app receive and process data asynchronously,
I have a little problem with a Listview. I can load it with listview
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,

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.