即时翻译DataGridComboBoxColumn

时间:2015-07-02 07:04:41

标签: c# wpf datagrid

我需要使用DataGridComboBoxColumn翻译WPFLocalizationExtension

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

public static List<ProfileSegmentType> AvailableSegmentTypes
{
  get
  {
    var availableSegmentTypes = new List<ProfileSegmentType>
    {
      new ProfileSegmentType { Value = ProfileSegmentTypeEnum.Arc },
      new ProfileSegmentType { Value = ProfileSegmentTypeEnum.Line },
    };
    return availableSegmentTypes;
  }
}

ProfileSegmentType看起来像这样:

public class ProfileSegmentType
{
  public ProfileSegmentTypeEnum Value { get; set; }
  public string Label
  {
    get { return Resources.Localization.ADummyValue; }
  }
}

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

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

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

1 个答案:

答案 0 :(得分:0)

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

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) => {};
}