Silverlight RadGridView未显示属性已更改
第一次被问到的问题是长期潜伏者 我正在开发一个Silverlight应用程序,其视图实现了RadGridView。我有一个ViewModel,它将人员技能的可观察集合绑定到RadGridView。在模型中,人员技能是多对一技能。描述是技能的一种属性。SkillId上有一个外键将它们连接起来(抱歉,没有足够的代表发布图像) RadGridView中的我的列绑定到Skill.Description属性。在我对此处未表示的数据表单进行编辑之前,一切正常。PersonSkills集合启动,我可以看到更改后的值,并将更改发布到数据库,但RadGridView显示的是一个空单元格,而不是应该显示的Skill.Description 我需要做什么才能让RadGridView反映对作为PersonSkills集合子级的技能集合的属性所做的更改Silverlight RadGridView未显示属性已更改,silverlight,viewmodel,inotifypropertychanged,radgridview,Silverlight,Viewmodel,Inotifypropertychanged,Radgridview,第一次被问到的问题是长期潜伏者 我正在开发一个Silverlight应用程序,其视图实现了RadGridView。我有一个ViewModel,它将人员技能的可观察集合绑定到RadGridView。在模型中,人员技能是多对一技能。描述是技能的一种属性。SkillId上有一个外键将它们连接起来(抱歉,没有足够的代表发布图像) RadGridView中的我的列绑定到Skill.Description属性。在我对此处未表示的数据表单进行编辑之前,一切正常。PersonSkills集合启动,我可以看到更改
<telerik:RadGridView
x:Name="skillsGrid"
ItemsSource="{Binding PersonSkills, Mode=TwoWay}"
SelectedItem="{Binding CurrentPersonSkill, Mode=TwoWay}"
ColumnWidth="*">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn
Header="SKILL"
DataMemberBinding="{Binding Skill.Description}"
IsGroupable="False"
Width="2*" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
private ObservableCollection<PersonSkill> personSkills;
public ObservableCollection<PersonSkill> PersonSkills
{
get
{
return this.personSkills;
}
set
{
this.personSkills = value;
this.OnUiThread(() =>
{
this.RaisePropertyChanged("PersonSkills","CurrentPersonSkill");
});
}
}
private PersonSkill currentPersonSkill;
public PersonSkill CurrentPersonSkill
{
get
{
return this.currentPersonSkill;
}
set
{
if (this.currentPersonSkill != value)
{
this.currentPersonSkill = value;
this.RaisePropertyChanged("PersonSkills","CurrentPersonSkill");
}
}
}
私人观察收集人员技能;
公众观察收集人员技能
{
得到
{
归还这个。个人技能;
}
设置
{
this.personSkills=值;
此.OnUiThread(()=>
{
此.RaisePropertyChanged(“人员技能”、“当前人员技能”);
});
}
}
私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人私人;
公共人员技能当前人员技能
{
得到
{
返回此.currentPersonSkill;
}
设置
{
if(this.currentPersonSkill!=值)
{
this.currentPersonSkill=值;
此.RaisePropertyChanged(“人员技能”、“当前人员技能”);
}
}
}
我应该提到我也在使用RadDatForm。这是罪魁祸首。我放弃了使用RadDataForm。更麻烦的是它的价值。相反,我通过viewmodel中的绑定命令实现了一个自制的数据表单。更干净的IMHO。希望它能帮助其他人
<Grid
x:Name="readOnlyForm"
Visibility="{Binding RequestFormInEdit, Converter={StaticResource InvertedBooleantToVisibilityConverter}}">
<StackPanel>
<TextBlock
Text="{Binding PersonSkill.Skill.Description}"/>
</StackPanel>
<StackPanel>
<telerik:RadButton
Command="{Binding AddCommand}"
Tag="ADD">
</telerik:RadButton>
<telerik:RadButton
Command="{Binding EditCommand}"
Tag="EDIT">
</telerik:RadButton>
</StackPanel>
</Grid>
<Grid
x:Name="editForm"
Visibility="{Binding FormInEdit, Converter={StaticResource BooleantToVisibilityConverter}}">
<Grid>
<StackPanel>
<Grid>
<TextBlock
Text="SKILL"/>
<TextBox Text="{Binding PersonSkill.Skill.Description, Mode=TwoWay}"/>
</Grid>
</StackPanel>
<StackPanel>
<telerik:RadButton
Tag="SAVE"
Command="{Binding SubmitCommand}">
</telerik:RadButton>
<telerik:RadButton
Tag="CANCEL"
Command="{Binding CancelCommand}">
</telerik:RadButton>
</StackPanel>
</Grid>
</Grid>
</Grid>
private bool FormInEdit;
public bool FormInEdit
{
get
{
return FormInEdit;
}
private set
{
if (FormInEdit != value)
{
FormInEdit = value;
RaisePropertyChanged("FormInEdit");
}
}
}
private DelegateCommand addCommand;
public DelegateCommand AddCommand
{
get
{
if (addCommand == null)
{
addCommand = new DelegateCommand(
OnAddCommand);
}
return addCommand;
}
}
private void OnAddCommand()
{
// create a new personskill code goes here
// and begin edit
FormBeginEdit();
}
private DelegateCommand editCommand;
public DelegateCommand EditCommand
{
get
{
if (editCommand == null)
{
editCommand = new DelegateCommand(
OnEditCommand);
}
return editCommand;
}
}
private void OnEditCommand()
{
if (CurrentPersonSKill != null)
{
if (FormInEdit)
{
}
else
{
FormBeginEdit();
}
}
}
private DelegateCommand cancelCommand;
public DelegateCommand CancelCommand
{
get
{
if (cancelCommand == null)
{
cancelCommand = new DelegateCommand(
OnCancelCommand,
() => (CurrentPersonSkill != null) && FormInEdit);
}
return cancelCommand;
}
}
private void OnCancelCommand()
{
if (CurrentPersonSkill != null)
{
FormCancelEdit();
}
FormEndEdit();
}
private DelegateCommand submitCommand;
public DelegateCommand SubmitCommand
{
get
{
if (submitCommand == null)
{
submitCommand = new DelegateCommand(
OnSubmitCommand,
() => (CurrentPersonSkill != null) && FormInEdit);
}
return submitCommand;
}
}
private void OnSubmitCommand()
{
if (CurrentPersonSkill != null)
{
//submit the PersonSkill here
FormEndEdit();
}
}
private void FormBeginEdit()
{
if CurrentPersonSkill != null)
{
FormInEdit = true;
}
}
private void FormEndEdit()
{
FormInEdit = false;
}
private void FormCancelEdit()
{
if CurrentPersonSkill != null)
{
FormInEdit = false;
}
}
private void OnViewModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "FormInEdit":
SubmitCommand.RaiseCanExecuteChanged();
CancelCommand.RaiseCanExecuteChanged();
break;
case "CurrentPersonSkill":
SubmitCommand.RaiseCanExecuteChanged();
CancelCommand.RaiseCanExecuteChanged();
break;
}
}