I’ve got a silverlight view (for lack of a better work) with some text boxes on it that have their values bound to entities exposed via a DomainService query (using silverlight 4, EF 4, and RIA Domain Services). I’ve got everything wired up and saving correctly based on values changing, but I need to include who is making the changes as well as the field bound to the control.
XAML:
<TextBox Name="txtComment" Text="{Binding Comment, Mode=TwoWay}" ></TextBox>
Initialization:
_dataContext.Load(accountingItemValues, (lo) =>
{
... Bind other boxes to entities
this.txtComment.DataContext = _dataContext.AccountingItemValues.First().STARS_DistrictInputData;
}, null);
Is there a good way of getting a handle to the entity that the control is bound to? I tried an implicit cast of the (myEntity)control.DataContext, but that didn’t work out. I’d like to be able to change the UpdatedBy property of the STARS_DistrictInputData as well as the Comment property explicitly bound in the xaml.
Update: The userId is available at the page, so I don’t need to query for it.
I found a work-around, but it seems hacky:
In the page I set up a private instantiation of the entity I wanted to bind to:
XAML:
Initialization:
Then I changed the .UpdatedBy property of the entity on the changed event of my textbox. Is there a way to do the double binding in the XAML?