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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:49:24+00:00 2026-06-15T08:49:24+00:00

I am using PostSharp’s [CompositionAspect] capability to dynamically inject an interface to a model

  • 0

I am using PostSharp’s [CompositionAspect] capability to dynamically inject an interface to a model object in my WPF application. However, it seems WPF cannot bind (display) properties corre ctly unless the relevant interface is explicitly implemented on the model object?

Using a custom CompositionAspect (ComposeObjectAspect) I am able to successfully expose the internal IMyInterface object’s properties directly by runtime casting the ModelObject to the introduced interface;

// some interface definition, for sample completeness
public interface IMyInterface 
{
    public string MyProperty { get; set; }
}


// model object, which does NOT implement IMyInterface directly, though the interface is dynamically introduced by PostSharp
[ComposeObjectAspect(typeof(IMyInterface))]
public class ModelObject 
{
    private IMyInterface actualDataObject;
}

. . .

public class ViewModel
{
    public ObservableCollection<IMyInterface> MyData { get; }

    public void LoadData()
    {
        // concrete IMyInterface dtos are returned here, and put into a VM collection
        IList<IMyInterface> myData = 
            (from IMyInterface o in SomeDataSource.LoadLocalDescriptors() 
             select new ModelObject(o) as IMyInterface).ToList();
        this.MyData = new ObservableCollection<IMyInterface>(myData);
    }
}

This all works fine, and if I inspect any object in the myData list, or cast it to the type IMyInterface (which as you can see form the class ModelObject definition above is not implemented directly), I can see the inner properties from actualDataObject directly. This all works great.

Now when I try to bind the ViewModel.Data collection to a WPF datagrid, I get a series of binding errors like;

System.Windows.Data Error: 40 : BindingExpression path error: ‘SomeProperty’ property not found on ‘object’ ”ModelObject’ (HashCode=56810243)’. BindingExpression:Path=SomeProperty; DataItem=’ModelObject’ (HashCode=56810243); target element is ‘TextBlock’ (Name=”); target property is ‘Text’ (type ‘String’)

For reference, the relevant section of the View XAML looks like;

<DataGrid ItemsSource="{Binding MyData}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Width="Auto" Header="Some Property" Binding="{Binding SomeProperty, Mode=OneWay}" />
    </DataGrid.Columns>
</DataGrid>

It is the grid columns which are appearing blank, though all data rows are visible (and empty).

If I inspect ‘ModelObject’, the property IMyInterface.SomeProperty is there.

If I directly apply IMyInterface to the ModelObject class (and implenment all members as simple relays to the composed actualDataObject instance) then the binding is fine, and SomeProperty displays without error.

What am I missing that is different between the PostSharp implementation of IMyInterface, and my own explicit version?

  • 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-15T08:49:26+00:00Added an answer on June 15, 2026 at 8:49 am

    I managed to find a solution to this problem here: WPF databinding to interface and not actual object – casting possible?

    Turns out the binding will work if it is defined explicitly against the interface type, instead of implicitly, presumably because ModelObject does not have a SomeProperty, but it does have IMyInterface.SomeProperty ?

    So, this works;

    <DataGridTextColumn Width="Auto" Header="Some Property" 
           Binding="{Binding Path=(mynamespace:IMyInterface.SomeProperty), Mode=OneWay}" />
    

    Though, it does cause designer warnings, as noted in the referenced question.

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

Sidebar

Related Questions

I am considering using Postsharp framework to ease the burden of application method logging.
I'm using the PostSharp Diagnostics Toolkit with Log4Net and it is working verynicely. However,
I am using postsharp to log method call and i need to log the
I am using PostSharp to add some compile time logic to my attributes -
I started playing with Postsharp but cannot get past the first step. Someone else
I am working on an WPF application that uses a BusinessLogic layer (currently a
I'm using PostSharp alternative called AfterThought to postprocess some of projects in my solution.
I'm about to start using PostSharp in my project. I'd like to leverage existing
Without using a library like PostSharp, is there a way to set up a
I am evaluating PostSharp for a new project but cannot seem to get past

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.