Bind DisplayMemberPath for function in WPF

Is there a way to bind DisplayMemberPath from combobox to function? The object I'm working with now has three properties that I want to use for presentation; FirstName , LastName and MiddleName .

I wrote a static method in a formatting class to handle it. This method is called FullName and takes three string arguments.

Is there a way I can call Formatting.FullName and pass three arguments from my Person object to display the formatted fully qualified name in list items on a list?

I added the following XAML section to the resource section of my page:

 <ObjectDataProvider ObjectType="{x:Type business:Formatting}" x:Key="formatter" /> <ObjectDataProvider ObjectInstance="{StaticResource formatter}" MethodName="FullName" x:Key="nameFormatter"> <ObjectDataProvider.MethodParameters> <system:String>Bloggs</system:String> <system:String>Joe</system:String> <system:String>Q</system:String> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> 

And my combobox XAML now looks like this:

 <ComboBox Height="23" Width="120" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="467,72,0,0" Name="cboDistrictAttorney" SelectedValuePath="Id" SelectedValue="{Binding DistrictAttorneyId}" DisplayMemberPath="{Binding Source={StaticResource nameFormatter}}" /> 

And the end result is that I have a combo box consisting of empty elements.

+4
source share
1 answer

Another case is a DataTemplate, but a DataTemplate for your application is heavier.

0
source

All Articles