I have a Silverlight Application with Domain Service.
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 :
<c1:Column x:Name="dgcDescription" Binding="{Binding Path=ShortDescription}" Width="4*" />
And a RichTextBox with :
<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.
Any Idea ? (I do not use MVVM, I use the Code Behind)
You need to tell the UI that the property ShortDescription
(an autocalculated property) has changed, when you change the property Description
.
In order to do that, you need to raise the PropertyChanged
-Event for the property ShortDescription
when the property Description
changed. Otherwise has the UI now chance to know that the property ShortDescription
has changed and that it should update the binding.
In CodeBehind (in Silverlight-Client-Project) you can do it like so:
public partial class AbroadTravel
// omitted your code
partial void OnDescriptionChanged(){
RaisePropertyChanged("ShortDescription");
}
}