いくつかの追加機能を備えたカスタムRadioButtonを作成しています。私は何とか "OnDataBound"イベントを購読する必要があります - これを行う方法はありますか?データバインド時にSilverlightラジオボタンを操作する必要があります
ありがとうございます!私は考えることができる
いくつかの追加機能を備えたカスタムRadioButtonを作成しています。私は何とか "OnDataBound"イベントを購読する必要があります - これを行う方法はありますか?データバインド時にSilverlightラジオボタンを操作する必要があります
ありがとうございます!私は考えることができる
最も簡単な方法:
1)CustomIsChecked
オブジェクトを保持DependencyProperty
でRadioButton
をカプセル化し、ユーザーコントロールの作成: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
}
をあなたのRadioButton
CustomIsChecked
への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>
すぐにこれを試してみましょう。あなたは私のために多くの問題を解決したかもしれません! –
this.DataContext = this; ?? Not this.DataContext = CustomDataContext? –
はい、私はあなたもそれを省略することができると確信しています。 CustomDataContextは内部のRadioButtonのためのものです –
こんにちは。どのプロパティのOnDataBound?すべてまたは何か特定のもの? –
IsCheckedがバインドされている場合。 –