2

PRISM リージョンがあります。

<ItemsControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.AdministrationCommandsRegion}">
    <ItemsControl.ItemTemplate>
        ...
    </ItemsControl.ItemTemplate>
</ItemsControl>

リージョンマネージャーを使用してビューモデルを追加しています:

_regionManager.Regions[RegionNames.AdministrationCommandsRegion].Add(new CommandViewModel("User Management", new DelegateCommand(RequestNavigate));

CommandViewModel次のようになります。

public class CommandViewModel
{
    public CommandViewModel(string displayName, ICommand command)
    {
        if (command == null) throw new ArgumentNullException("command");

        DisplayName = displayName;
        Command = command;
    }

    public string DisplayName { get; private set; }
    public ICommand Command { get; private set; }
}

リージョン内の の順序を指定したいのですが、インスタンスごとに異なるようにの属性CommandViewModelsを指定する方法が見つかりません。属性に依存する代わりに、ViewSortHint をコンストラクターに渡す方法はありますか?ViewSortHintCommandViewModelCommandViewModel

4

1 に答える 1

3

属性を使用する代わりに、地域のプロパティViewSortHintを使用して並べ替えの問題を解決できます。SortComparison

ViewModelを並べ替えるために、プロパティをデリゲート メソッドにSortComparison設定できます。Comparison<object>

this._regionManager.Regions["MyRegion"].SortComparison = CompareViewModels;

この比較は、関連するViewModelsのインターフェイスSortIndexなどを実装するプロパティで行うことができます。したがって、デリゲート メソッドはプロパティを比較します。ISortableISortable SortIndex

private static int CompareViewModels(object x, object y)
{
  ISortable xSortable = (ISortable) x;
  ISortable ySortable = (ISortable) y;
  return xSortable.SortIndex.CompareTo(ySortable.SortIndex);
}

最後に、SortIndex値をViewModelコンストラクターに渡し、ISortable各インスタンスのプロパティを設定できます。

詳細については、次の Prism ガイドの章を参照してください。

お役に立てれば。

于 2013-10-02T16:52:30.680 に答える