首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即时翻译DataGridComboBoxColumn

即时翻译DataGridComboBoxColumn
EN

Stack Overflow用户
提问于 2015-07-02 15:04:41
回答 1查看 82关注 0票数 0

我有一个需要用WPFLocalizationExtension翻译的DataGridComboBoxColumn

我的视图模型中有一个静态方法,它提供了可用的值:

代码语言:javascript
复制
public static List<ProfileSegmentType> AvailableSegmentTypes
{
  get
  {
    var availableSegmentTypes = new List<ProfileSegmentType>
    {
      new ProfileSegmentType { Value = ProfileSegmentTypeEnum.Arc },
      new ProfileSegmentType { Value = ProfileSegmentTypeEnum.Line },
    };
    return availableSegmentTypes;
  }
}

ProfileSegmentType如下所示:

代码语言:javascript
复制
public class ProfileSegmentType
{
  public ProfileSegmentTypeEnum Value { get; set; }
  public string Label
  {
    get { return Resources.Localization.ADummyValue; }
  }
}

我的数据网格列定义如下所示:

代码语言:javascript
复制
<DataGridComboBoxColumn Header="..."
                        ItemsSource="{Binding Source={x:Static viewModels:ProfileGeometryViewModel.AvailableSegmentTypes}}"
                        SelectedValueBinding="{Binding SegmentType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        SelectedValuePath="Value"
                        DisplayMemberPath="Label" />

现在我得到了标签的翻译(现在是虚拟值)。当然,当我切换语言时,单元格不会更新。当我切换语言时,如何实现单元格内容的更新?(我也尝试使用值转换器,但无法以这种方式工作)

EN

回答 1

Stack Overflow用户

发布于 2015-07-02 16:56:17

在你的评论的帮助下,我可以解决它。我不得不这样修改我的ProfileSegmentType

代码语言:javascript
复制
public class ProfileSegmentType : INotifyPropertyChanged
{
  public ProfileSegmentType()
  {
    LocalizeDictionary.Instance.PropertyChanged += (e, a) =>
    {
      if (a.PropertyName == "Culture")
        PropertyChanged(this, new PropertyChangedEventArgs("Label"));
    };
  }
  public ProfileSegmentTypeEnum Value { get; set; }

  public string Label
  {
    get { return Common.Resources.Localization.Add; }
  }

  public event PropertyChangedEventHandler PropertyChanged = (e, a) => {};
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31177675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档