[英]Custom Entity object property doesn't update in Silverlight DataGrid
I have a Silverlight Application with Domain Service. 我有一个带有域服务的Silverlight应用程序。
Entity Object (Part Of) : 实体对象(的一部分):
[EdmEntityTypeAttribute(NamespaceName="MiaoulisModel", Name="AbroadTravel")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class AbroadTravel : EntityObject
{
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Description
{
get
{
return _Description;
}
set
{
OnDescriptionChanging(value);
ReportPropertyChanging("Description");
_Description = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Description");
OnDescriptionChanged();
}
}
private global::System.String _Description;
partial void OnDescriptionChanging(global::System.String value);
partial void OnDescriptionChanged();
Here is my Partial Classe with Custom Property : 这是我的部分自定义属性类:
public partial class AbroadTravel : INotifyPropertyChanged
{
[DataMember]
public String ShortDescription
{
get
{
if (this.Description == null)
{
return this.Description;
}
if (this.Description.Contains("\n"))
{
var index = this.Description.IndexOf("\n");
if (index < 50)
{
return this.Description.Substring(0, index) + " [...]";
}
}
if (this.Description.Length >= 50)
{
return this.Description.Substring(0, 50) + " [...]";
}
return this.Description;
}
}
}
In my DataGrid, I have : 在我的DataGrid中,我有:
<c1:Column x:Name="dgcDescription" Binding="{Binding Path=ShortDescription}" Width="4*" />
And a RichTextBox with : 还有一个RichTextBox与:
<c1:C1RichTextBox Text="{Binding Path=Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
When I update the RichTextBox which the Description value, the DataGrid with the ShortDescription does not update. 当我更新描述值的RichTextBox时,带有ShortDescription的DataGrid不会更新。
Any Idea ? 任何想法 ? (I do not use MVVM, I use the Code Behind)
(我不使用MVVM,我使用后面的代码)
You need to tell the UI that the property ShortDescription
(an autocalculated property) has changed, when you change the property Description
. 当您更改属性
Description
时,您需要告诉UI属性ShortDescription
(自动计算的属性)已更改。
In order to do that, you need to raise the PropertyChanged
-Event for the property ShortDescription
when the property Description
changed. 为此,当属性
Description
更改时,需要为属性ShortDescription
引发PropertyChanged
-Event。 Otherwise has the UI now chance to know that the property ShortDescription
has changed and that it should update the binding. 否则,UI现在有机会知道属性
ShortDescription
已更改,并且应该更新绑定。
In CodeBehind ( in Silverlight-Client-Project ) you can do it like so: 在CodeBehind( 在Silverlight-Client-Project中 )中,您可以像这样进行操作:
public partial class AbroadTravel
// omitted your code
partial void OnDescriptionChanged(){
RaisePropertyChanged("ShortDescription");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.