我有一个带有绑定到数据上下文的域服务的网格。我想刷新数据上下文。
我有代码:
<Grid DataContext="{Binding Data, ElementName=userDomainDataSource}" Name="gridAccountDetails">
<sdk:Label Content="Address Line" HorizontalAlignment="Left" Margin="443,67,0,0" d:LayoutOverrides="VerticalAlignment" VerticalAlignment="Top" />
<TextBox HorizontalAlignment="Left" Margin="537,59,0,0" x:Name="txtAccountDetailsAddress" Text="{Binding addressline, Mode=OneWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" d:LayoutOverrides="VerticalAlignment" Height="24" VerticalAlignment="Top" DataContext="{Binding}" />
<sdk:Label Content="County" HorizontalAlignment="Left" Margin="443,142,0,143" d:LayoutOverrides="Height" />
<TextBox HorizontalAlignment="Left" Margin="537,134,0,143" x:Name="txtAccountDetailsCounty" Text="{Binding county, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" />
<sdk:Label Content="Email" HorizontalAlignment="Left" Margin="26,143,0,142" d:LayoutOverrides="HorizontalAlignment, Height" />
<TextBox HorizontalAlignment="Left" Margin="114,136,0,142" x:Name="txtAccountDetailsEmail" Text="{Binding email, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" d:LayoutOverrides="HorizontalAlignment" />
<sdk:Label Content="First Name" HorizontalAlignment="Left" Margin="26,67,0,0" VerticalAlignment="Top" />
<TextBox HorizontalAlignment="Left" Margin="114,60,0,0" x:Name="txtAccountDetailsFirstname" Text="{Binding firstname, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" Width="233" Height="23" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment" />
<sdk:Label Content="Last Name" HorizontalAlignment="Left" Margin="26,104,0,0" VerticalAlignment="Top" />
<TextBox HorizontalAlignment="Left" Margin="114,97,0,0" x:Name="txtAccountDetailsLastname" Text="{Binding lastname, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" Height="23" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment" />
<sdk:Label Content="Postcode" HorizontalAlignment="Left" Margin="443,0,0,104" VerticalAlignment="Bottom" />
<TextBox HorizontalAlignment="Left" Margin="537,0,0,104" x:Name="txtAccountDetailsPostcode" Text="{Binding postcode, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" Height="24" VerticalAlignment="Bottom" />
<sdk:Label Content="Town" Margin="0,105,323,0" VerticalAlignment="Top" HorizontalAlignment="Right" />
<TextBox HorizontalAlignment="Left" Margin="537,0,0,180" x:Name="txtAccountDetailsTown" Text="{Binding town, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" Width="233" Height="24" VerticalAlignment="Bottom" />
<Button Content="Edit Account Details" HorizontalAlignment="Right" Margin="0,0,26,35" VerticalAlignment="Bottom" Width="136"/>
</Grid>
我已使用以下代码设置域源:
EntityQuery<Web.User> qry =
from u in usrClass.getQuery()
where u.userId == usrClass.getUserId()
select u;
LoadOperation<Web.User> loadU = usrClass.loadUsersQuery(qry);
userDomainDataSource.DataContext = loadU.Entities;
我尝试过使用:
gridAccountDetails.DataContext = userDomainDataSource.DataContext;
和
gridAccountDetails.DataContext = userDomainDataSource.Data;
没有运气
但是我想刷新数据源,以便将新值放入文本框中,因为这些值可以由用户更改。
任何人都可以提供任何信息。感谢
答案 0 :(得分:0)
嗯,你必须告诉“gridAccountDetails”“userDomainDataSource”的“数据”发生了变化。最广泛使用的是提升PropertyChanged事件,尽管我不确定这将如何适合您的服务,可能会考虑从服务到您的网格的缓冲区。
一旦绑定了一件事,我就不会触及Grid的datacontext,你绑定它然后覆盖。