相关疑难解决方法(0)

如何将"IsDirty"属性添加到LINQ to SQL实体?

我将我的实体绑定到WPF中的编辑表单.在DataTemplate中,我希望能够在DataTemplate中设置根容器的背景颜色,以显示它已被更改,并且这些更改尚未提交到数据库.

这是一个非常简单的示例,演示了我正在谈论的内容(原谅错误):

<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>
Run Code Online (Sandbox Code Playgroud)

这个例子只打印出"我是肮脏的吗?是的"还是"我是不是很脏?没有",但你明白了.

为此,我需要向我的Item(partial class,simple)添加一个公共属性,以确定实体是否脏.这是艰难的一点.

public partial class Item
{
    public bool IsDirty
    {
        get
        {
            throw new NotImplementedException("hurf durf");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在实体之外,它非常简单(只要你有附加实体的DataContext …

wpf binding dirty-data linq-to-sql

2
推荐指数
1
解决办法
1605
查看次数

标签 统计

binding ×1

dirty-data ×1

linq-to-sql ×1

wpf ×1