2012-01-09 5 views
1

いくつかの追加機能を備えたカスタムRadioButtonを作成しています。私は何とか "OnDataBound"イベントを購読する必要があります - これを行う方法はありますか?データバインド時にSilverlightラジオボタンを操作する必要があります

ありがとうございます!私は考えることができる

+0

こんにちは。どのプロパティのOnDataBound?すべてまたは何か特定のもの? –

+0

IsCheckedがバインドされている場合。 –

答えて

0

最も簡単な方法:

1)CustomIsCheckedオブジェクトを保持DependencyPropertyRadioButtonをカプセル化し、ユーザーコントロールの作成:UserControl、バインドのXAMLの一部で

/// <summary> 
    /// Interaction logic for CustomRadioButton.xaml 
    /// </summary> 
    public partial class CustomRadioButton : UserControl 
    { 
     public CustomRadioButton() 
     { 
      InitializeComponent(); 
      this.DataContext = this; 
     } 

     #region CustomIsChecked 
     public bool CustomIsChecked 
     { 
      get { return (bool)GetValue(CustomDataContextProperty); } 
      set { SetValue(CustomDataContextProperty, value); } 
     } 

     // Using a DependencyProperty as the backing store for CustomIsChecked. This enables animation, styling, binding, etc... 
     public static readonly DependencyProperty CustomIsCheckedProperty = 
      DependencyProperty.Register("CustomIsChecked", typeof(bool), typeof(CustomRadioButton), new UIPropertyMetadata(new PropertyChangedCallback((dpo, dpce) => 
      { 
       MessageBox.Show("IsChecked has changed!"); 
      }))); 
     #endregion 
    } 

をあなたのRadioButtonCustomIsCheckedへのIsChecked

<UserControl x:Class="WpfApplication1.CustomRadioButton" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"> 
    <RadioButton IsChecked="{Binding CustomIsChecked, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" /> 
</UserControl> 

+0

すぐにこれを試してみましょう。あなたは私のために多くの問題を解決したかもしれません! –

+0

this.DataContext = this; ?? Not this.DataContext = CustomDataContext? –

+0

はい、私はあなたもそれを省略することができると確信しています。 CustomDataContextは内部のRadioButtonのためのものです –