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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:36:18+00:00 2026-06-06T07:36:18+00:00

I build up a Office 2010 Word Add In, added a Windows Forms Element

  • 0

I build up a Office 2010 Word Add In, added a Windows Forms Element to it and there in an ElementHost object containing my WPF.

That’s the problem:
I got the problem, that common properties (DP’s) defined in the Xaml code and set in the ViewModel implementation (see code below) are not updated, even if I can’t find any wrong code while debugging. This applies only to the properties I got, furthermore i got some
ObservableCollection<> List’s which are updated without any problems. Got anybody an idea? I red that I may define the properties by myself within the Code using something like this:

public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register("DataSource",typeof(string),typeof(usercontrol1));

But this does not work too (I just added this line for example into the code-behind file of the Xaml file – and left anything else at it is)

My code looks this way:

Constructor of the Forms Element (it’s actually private because I implemented it as Singleton):

private Sidebar()
{
    InitializeComponent();
    this.DoubleBuffered = true;

    _wpfHost = new ElementHost();
    _wpfHost.Dock = DockStyle.Fill;

    _wpfUserControl = new WPFUI();

    _wpfHost.Child = _wpfUserControl;

    this.Controls.Add(_wpfHost);
}

Furthermore I created an underlying ViewModel and set this as DataContext Property of the WPFUI like this (it’s also a Singleton implementation because I wanted to access in a further implementation the same instance from several places, but this does not come into the game at this time):

public WPFUI()
{
    InitializeComponent();

    this.DataContext = myViewModel.GetInstance();
}

My ViewModel properties are defined and used this way:

public ObservableCollection<myListViewItem> PeopleEntityResultObjects { get; private set; }

private string _NumberOfPeople;
public string NumberOfPeople
{
    get { return _NumberOfPeople; }
    set { SetField(ref _NumberOfPeople, value, () => NumberOfPeople); }
}

And finally the Xaml looks like this:

<TabControl>
    <TabItem>
        <TabItem.Header>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text=" People "/>
                <TextBlock Text="{Binding Path=NumberOfPeople}"/>
            </StackPanel>
        </TabItem.Header>

        <ScrollViewer x:Name="PeopleListScrollViewer">
            <ListView Name="PeopleListView" ItemsSource="{Binding Path=PeopleEntityResultObjects, Mode=OneWay}" IsSynchronizedWithCurrentItem="True">
            .
            .
            .
            </ListView>
        </ScrollViewer>
    </TabItem>
</TabControl>

Why is my ObservableCollection<> List updating but not the bound properties like

<TextBlock Text="{Binding Path=NumberOfPeople}"/>

? Can anybody guess, or i’m missing some basic property definition? (in a wpf application it is working that way).

EDIT

SetField() implementation:

protected virtual void OnPropertyChanged<T>(Expression<Func<T>> selectorExpression)
{
    if (selectorExpression == null)
        throw new ArgumentNullException("selectorExpression");

    MemberExpression body = selectorExpression.Body as MemberExpression;

    if (body == null)
        throw new ArgumentException("The body must be a member expression");

    OnPropertyChanged(body.Member.Name);
}

protected virtual void OnPropertyChanged(string propertyName)
{
    PropertyChangedEventHandler handler = PropertyChanged;

    if (handler != null) 
        handler(this, new PropertyChangedEventArgs(propertyName));
}

protected bool SetField<T>(ref T field, T value, Expression<Func<T>> selectorExpression)
{
    if (EqualityComparer<T>.Default.Equals(field, value)) return false;

    field = value;

    OnPropertyChanged(selectorExpression);

    return true;
}       

Regards,
Thomas

  • 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-06T07:36:20+00:00Added an answer on June 6, 2026 at 7:36 am

    using the dispatcher object, already used to insert item’s into the UI bound list, is the key to accomplish this task successfully:

    if (DispatcherObject.Thread != Thread.CurrentThread)
        DispatcherObject.Invoke(new Action(() => SetField(ref _numberOfPeople, value, () => NumberOfPeople)));
    else
        SetField(ref _numberOfPeople, value, () => NumberOfPeople);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just built an MS Outlook Add In using Visual Studio and Office 2010.
I am using Interop.Microsoft.Office.Interop.Word.dll to dynamically build a Word document in C#. Does anyone
i want to build an app for windows mobile that can get GPS locations(longitude
I have a personal project that I'd like to build as an add-in for
I created a WiX installer deploying an add in for Windows 2010. Target system
Setup: Windows 7 64-bit Office 2010 Professional 64-bit Visual Studio 2010 Professional Using Connection
I've started to build a Windows Forms application. The application will work in two
I want to build an add-in for Office applications using VSTO. I want to
Presently I am attempting to build a tool that will open a Microsoft Word
I build VBA applications for both Word and Excel, is there any way to

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.