@@ -54,7 +54,11 @@ public object Header
5454 /// <summary>
5555 /// Gets the text to display in the link.
5656 /// </summary>
57- public string LinkText => ( string ) GetValue ( LinkTextProperty ) ;
57+ public string LinkText
58+ {
59+ get { return ( string ) GetValue ( LinkTextProperty ) ; }
60+ private set { SetValue ( LinkTextPropertyKey , value ) ; }
61+ }
5862
5963 protected override void OnSelectionChanged ( SelectionChangedEventArgs e )
6064 {
@@ -69,7 +73,33 @@ private static void HeaderChanged(DependencyObject d, DependencyPropertyChangedE
6973
7074 private void UpdateLinkText ( )
7175 {
72- SetValue ( LinkTextPropertyKey , SelectedItem ? . ToString ( ) ?? Header ? . ToString ( ) ) ;
76+ if ( SelectedItem != null )
77+ {
78+ var item = SelectedItem ;
79+
80+ // HACK: The correct way to do this is to use a ContentPresenter in the control
81+ // template to display the link text and do a:
82+ //
83+ // ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
84+ //
85+ // to correctly display the DisplayMemberPath. However I couldn't work out how
86+ // to do it like this and get the link text looking right. This is a hack that
87+ // will work as long as DisplayMemberPath is just a property name, which is
88+ // all we need right now.
89+ if ( string . IsNullOrWhiteSpace ( DisplayMemberPath ) )
90+ {
91+ LinkText = item . ToString ( ) ;
92+ }
93+ else
94+ {
95+ var property = item . GetType ( ) . GetProperty ( DisplayMemberPath ) ;
96+ LinkText = property ? . GetValue ( item ) ? . ToString ( ) ;
97+ }
98+ }
99+ else
100+ {
101+ LinkText = Header . ToString ( ) ;
102+ }
73103 }
74104 }
75105}
0 commit comments