I have a RadSplitButton on my form. The RadSplitButton's DropDownContent contains a RadContextMenu. Here's a snippet of the xaml:
In the Window's constructor, after calling InitializeComponent, I create an ObservableCollection and assign it to RejectionReasons. I then populate that ObservableCollection with ItemChoice objects:
But the RadContextMenu's Items collection remains empty, even after I populate the collection. I use this same ItemChoice class with ComboBoxes and ListBoxes and it works fine. What am I doing wrong?
Also, in my RadMenuItem.Click handler, how do I get a reference to the ItemChoice that generated the RadMenuItem? It's not at all clear to me from the properties that are available in that class.
Tony
<
telerik:RadSplitButton
Background
=
"{DynamicResource ButtonBackground}"
Click
=
"MisreadButton_Click"
CloseOnEscape
=
"False"
Content
=
"INCORRECT"
DropDownIndicatorVisibility
=
"Visible"
DropDownPlacement
=
"Top"
FontSize
=
"20"
FontWeight
=
"Bold"
Foreground
=
"{DynamicResource ButtonForeground}"
Height
=
"60"
HorizontalAlignment
=
"Right"
IsEnabled
=
"False"
Margin
=
"10"
Name
=
"IncorrectButton"
VerticalAlignment
=
"Center"
Width
=
"200"
>
<
telerik:RadSplitButton.DropDownContent
>
<
tl:RadContextMenu
DisplayMemberPath
=
"Value"
ItemsSource
=
"{Binding Path=RejectionReasons, RelativeSource={RelativeSource AncestorType={x:Type c:AlarmsDialog}}}"
tl:RadMenuItem.Click
=
"RadContextMenu_ItemClick"
/>
</
telerik:RadSplitButton.DropDownContent
>
</
telerik:RadSplitButton
>
public class ItemChoice<
TKey
> : INotifyPropertyChanged {
private TKey iKey;
public TKey Key {
get { return iKey; }
set {
iKey = value;
if ( PropertyChanged != null ) {
PropertyChangedEventArgs e = new PropertyChangedEventArgs( "Key" );
PropertyChanged( this, e );
}
}
}
private string iValue = string.Empty;
public string Value {
get { return iValue; }
set {
iValue = value;
if ( PropertyChanged != null ) {
PropertyChangedEventArgs e = new PropertyChangedEventArgs( "Value" );
PropertyChanged( this, e );
}
}
}
public ItemChoice() {}
public ItemChoice( TKey key, string value ) {
Key = key;
Value = value;
}
public ItemChoice( KeyValuePair<
TKey
, string> item ) {
Key = item.Key;
Value = item.Value;
}
public override string ToString() {
return Value.ToString();
}
public static explicit operator KeyValuePair<
TKey
, string>( ItemChoice<
TKey
> item ) {
return new KeyValuePair<
TKey
, string>( item.Key, item.Value );
}
public event PropertyChangedEventHandler PropertyChanged;
}
But the RadContextMenu's Items collection remains empty, even after I populate the collection. I use this same ItemChoice class with ComboBoxes and ListBoxes and it works fine. What am I doing wrong?
Also, in my RadMenuItem.Click handler, how do I get a reference to the ItemChoice that generated the RadMenuItem? It's not at all clear to me from the properties that are available in that class.
Tony