2010-11-28 12 views
1

私はINotifyPropertyChangedを実装し、SelectedTopicDescriptionプロパティを持ち、テキストプロパティTextプロパティをこのパブリックプロパティにバインドしようとしています。私はプロパティが変更されているが、テキストボックスが更新されていないことを知っている。SilverlightテキストボックスプロパティをUserControlのpublicプロパティにバインドする問題

私はいくつかのことを試しましたが、これは簡単であるはずです。

私はUserControl xaml内で以下のdatacontextを使用しようとしましたが、何の効果もありませんでした。私は依存性の適切性について読んだことがありますが、私はINotifyPropertyChangedを使ってこれを行うことはできませんか?

あなたのお手伝いがありがとうございます。

のDataContext = "{バインディングRelativeSource = {RelativeSource自己}}"

public partial class CodePage : UserControl ,INotifyPropertyChanged{ 

    private string _selectedTopicDescription = string.Empty; 
    public string SelectedTopicDescription { 
     get { return _selectedTopicDescription; } 
     set { 
      _selectedTopicDescription = value; 
      OnPropertyChanged("SelectedTopicDescription"); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 
    protected virtual void OnPropertyChanged(string property) { 
     PropertyChangedEventHandler ph = this.PropertyChanged; 
     if (ph != null) 
      ph(this, new PropertyChangedEventArgs(property)); 
    } 

...

テキストボックスである.. 幅= "200" 証拠金= "141,142,0,153" テキスト= "{バインディングSelectedTopicDescription}" たHorizo​​ntalAlignment = "左">

+0

コードで直接DataContextを割り当てようとしましたか? –

答えて

2

DataContextの要素をUserControlのUserControlのプロパティでバインドするときには、それを避けるのは良い考えではないでしょう。

<TextBox Text="{Binding Parent.SelectedTopicDescription, ElementName=LayoutRoot, Mode=TwoWay}" /> 

これは、ユーザーコントロールのContent要素が名前「LayoutRoot」を持っているという事実を使用し、そのターンにいる - は:代わりにこのように、BindingElementNameプロパティを経由してユーザーコントロールへの直接結合FrameworkElementは、UserControlとなるParentプロパティを持ちます。

0

モード=双方向、データバインドXAML式で

関連する問題