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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:05:23+00:00 2026-05-12T05:05:23+00:00

I am binding my entities to an edit form in WPF. Within a DataTemplate,

  • 0

I am binding my entities to an edit form in WPF. Within a DataTemplate, I want to be able to set the background color of the root container within a DataTemplate to show it has been changed and these changes have not yet been submitted to the database.

Here’s a very simple sample that demonstrates what I’m talking about (forgive errors):

<Page ...>
    <Page.DataContext>
        <vm:MyPageViewModel /> <!-- Holds reference to the DataContext -->
    </Page.DataContext>
    <ItemsControl
        ItemsSource = {Binding Items}>
        <ItemsControl.Resources>
            <DataTemplate
                DataType="Lol.Models.Item"> <!-- Item is L2S entity -->
                <!-- In real life, I use styles to set the background color -->
                <TextBlock Text="{Binding IsDirty, StringFormat='Am I dirty? /{0/}'}"/>
            </DataTemplate>
        </ItemsControl.Resources>
    </ItemsControl>
</Page>

The example just prints out “Am I dirty? yes” or “Am I dirty? no”, but you get the idea.

To do this, I’ll need to add a public property to my Item (partial class, simple) that can determine if the entity is dirty or not. This is the tough bit.

public partial class Item
{
    public bool IsDirty
    {
        get
        {
            throw new NotImplementedException("hurf durf");
        }
    }
}

Outside of the entity, it’s pretty simple (as long as you have the DataContext the entity is attached to). Inside, not so much.

What are my options here?


Edit: I don’t think there’s one good solution here, so suggestions for workarounds are welcome.

(Okay, similar questions exist, but they are all about how to determine this from outside of the entity itself and use the DataContext the entity is attached to.)

  • 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-12T05:05:23+00:00Added an answer on May 12, 2026 at 5:05 am

    If you are using the dbml generated classes, you should be able to implement a couple of partial methods like this:

    public partial class SampleEntity
    {
        partial void OnCreated()
        {
            this.IsDirty = true;
        }
    
        partial void OnLoaded()
        {
            this.PropertyChanged += (s, e) => this.IsDirty = true;
            this.IsDirty = false;
        }
    
        public bool IsDirty { get; private set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple DataTemplate <Grid.Resources> <HierarchicalDataTemplate ItemsSource={Binding Items} DataType={x:Type entities:Folder} ItemContainerStyle={StaticResource FileComponentItem}> <Grid
The Binding syntax, {Binding /} , works in WPF but does not work at
I'm having problems binding on a form with multiple models being submitted. I have
I have implemented IDataErrorInfo interface to validate my entities. <TextBox Text={Binding User.Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}
I created a filter form to limit the entities shown in a list. It
Is there any way to properly bind to a Set on a form? I'm
I have a DataGrid that binding an ObservableCollection of self tracking entities Users can
I have a WCF client which passes Self-Tracking Entities to a WPF application built
I am well aware of the INotifyPropertyChanged and INotifyCollectionChanged for WPF binding. This has
I've a form in which I only have to choose between several entities. So

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.