助けが必要です!
カスタム コントロールを作成し、DependencyProperty
次のタイプを追加しました。
Dictionary<string,int>
コントロールが保持されている XAML から、データ バインディングを実行して、コントロールの外側のディクショナリにバインドします。
ここにいくつかのコード スニペットがあります: カスタム コントロールを保持するコントロールのビュー モデル
private Dictionary<string, int> _wordsList;
public Dictionary<string, int> WordsList
{
get
{
return _wordsList;
}
set
{
_wordsList = value;
RaisePropertyChanged("WordsList");
}
}
public WordsViewModel()
{
//CalculateWordsDictionary returns a dictionary<string,int>
WordsList = CalculateWordsDictionary(texts);
}
XAML:
<local:MyControl WordsList="{Binding Path=WordsList}" />
カスタム コントロールの背後にあるコード:
public Dictionary<string, int> WordsList
{
get { return (Dictionary<string, int>)GetValue(WordsListProperty); }
set { SetValue(WordsListProperty, value); }
}
// Using a DependencyProperty as the backing store for WordsList. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WordsListProperty =
DependencyProperty.Register("WordsList", typeof(Dictionary<string, int>), typeof(MyControl), new PropertyMetadata(new Dictionary<string, int>()));
のセットにブレーク ポイントを設定しましたが、DependencyProperty
このポイントに到達しません。
これが機能しない理由がわかりません...または、辞書をコントロールに渡す他の方法がありますか?
ところで私はMVVM Lightを使用しています