将Country列绑定到整个数据条目,并使用converter显示只读值:如果它来自DB,则未修改,否则从dictionary获取。
<Window.Resources>
<local:ValueConverter x:Key="convResName"/>
</Window.Resources>
...
<telerik:GridViewDataColumn Header="Country" DataMemberBinding="{Binding}">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Converter={StaticResource convResName}, ConverterParameter={StaticResource {x:Static local:YourViewModel.yourDictAsStaticProperty}}}" />
</StackPanel>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
public class ValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var person = value as Person;
if (person==null)
{
return null;
}
var dict = parameter as Dictionary<string, string>;
if (string.IsNullOrWhiteSpace(person.Country))
{
try
{
person.Country = dict[person.Code];
}
catch (KeyNotFoundException exc)
{
//handle exc
}
}
return person.Country;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}