Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

bind multiple variables from list to one combobox

I Just start learn WPF and c#

        private void TransferAccountButtonClick(object sender, RoutedEventArgs e)
    {
        List<Client> allClients = Client.JsonToList();
        TransferStackPanel.Visibility = Visibility.Visible;

        TransferNameCombobox.DataContext = allClients;
        TransferNameCombobox.DisplayMemberPath = "surname";
    }

I need to display multiple fields in combox. Something like

TransferNameCombobox.DisplayMemberPath = "surname" + " " + "name" + " " + "patronymic";

If I do this it will show empty fields.
I understand that "surname" is not a string, but I don’t understand how to do it

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

in xaml I only have

<ComboBox x:Name="TransferNameCombobox" ItemsSource="{Binding}"/>

>Solution :

Instead of TransferNameCombobox.DataContext = allClients; make it TransferNameCombobox.ItemsSource = allClients; and delete TransferNameCombobox.DisplayMemberPath = "surname";

And then in the xaml, use this MultiBinding structure:

        <ComboBox x:Name="TransferNameCombobox">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0}, {1}, {2}">
                                <Binding Path="surname"/>
                                <Binding Path="name"/>
                                <Binding Path="patronymic"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading