Question

I have a listBox that bind to a class in my view model. This class has many properties but I would like to show two of them in my listBox.

I see that example (post)

The main code is this:

<ListBox ItemsSource="{Binding PersonList}">
      <ListBox.ItemTemplate>
         <DataTemplate>
            <TextBlock>
               <TextBlock.Text>
                  <MultiBinding Converter="{StaticResource mvc}"
                                ConverterParameter=", ">
                     <Binding Path="LastName"/>
                     <Binding Path="FirstName"/>
                  </MultiBinding>
               </TextBlock.Text>
            </TextBlock>
         </DataTemplate>

      </ListBox.ItemTemplate>
   </ListBox>

My problem is that when I try to use it, the is not avaliable in my axml. So I can't continue with the code.

Why Have I not avaliable the Multibinding?

My axml is:

<ListBox HorizontalAlignment="Stretch" Margin="5,41,0,0" Name="lsbPersonas" VerticalAlignment="Stretch" Grid.Row="1"
                 ItemsSource="{Binding Personas}"
                 SelectionMode="Extended" Height="112">


            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <TextBlock.Text>
                            <Multibinding ???? (I don't have this avaliable)
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
</ListBox>

Thanks.

Was it helpful?

Solution

You may not have added an appropriate binding converter to your project (like the static resource mvc from the code sample).

Fortunately it isn't even necessary. You could set the MultiBinding's StringFormat property instead:

<TextBlock.Text>
    <MultiBinding StringFormat="{}{0}, {1}">
        <Binding Path="LastName"/>
        <Binding Path="FirstName"/>
    </MultiBinding>
</TextBlock.Text>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top