我正在创建一个具有一些附加功能的自定义RadioButton。我需要以某种方式订阅“OnDataBound”事件 - 有这样的方法吗?
谢谢!
答案 0 :(得分:0)
我能想到的最简单的方法:
1)创建一个UserControl,用RadioButton
封装DependencyProperty
,其中包含CustomIsChecked
个对象:
/// <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
}
在UserControl
的XAML部分中,将IsChecked
的{{1}}绑定到RadioButton
:
CustomIsChecked
瞧!