Caliburn micro(1.3)/MVVM と Silverlight を使用しています。itemsource RadGridView を更新すると、選択した項目が失われます。MVVM実装時に選択項目を保存する動作を実装しているブログを見つけました。選択したアイテムを取得できますが、アイテムソースが更新されると元に戻すことはできません。caliburn.micro と RadGridView を使用してこれを実装する方法を教えてもらえますか? 最善の方法は caliburn マイクロ コンベンションを作成することだと思いますが、selectedItems ではなく、selectedItem の規約を作成するためのリファレンスしか見つかりません。
誰かがこれを達成する方法を教えてもらえますか? 以下を試してみましたが、うまくいきません。
private static void SetRadGridSelecteditemsConventions()
{
ConventionManager
.AddElementConvention<DataControl>(DataControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
.ApplyBinding = (viewModelType, path, property, element, convention) =>
{
ConventionManager.SetBinding(viewModelType, path, property, element, convention, DataControl.ItemsSourceProperty);
if (ConventionManager.HasBinding(element, DataControl.SelectedItemProperty))
return true;
var index = path.LastIndexOf('.');
index = index == -1 ? 0 : index + 1;
var baseName = path.Substring(index);
foreach (var selectionPath in
from potentialName in ConventionManager.DerivePotentialSelectionNames(baseName)
where viewModelType.GetProperty(potentialName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null
select path.Replace(baseName, potentialName))
{
var binding = new Binding(selectionPath) { Mode = BindingMode.TwoWay };
BindingOperations.SetBinding(element, DataControl.SelectedItemProperty, binding);
}
return true;
};
}
ありがとう、ステファン