Home > Software design >  WPF - How to properly Binding Header Items Count property of another component custom text
WPF - How to properly Binding Header Items Count property of another component custom text

Time:01-31

I want to put a counter and a description on a TabItem Header:

<TabItem  Header="{Binding ElementName=lista_etapas, Path=Items.Count,StringFormat=Etapas: {0}}">

But the StringFormat doesn't work. It only shows the Item Count property of the Datagrid 'lista_etapas'.

Expected: 'Etapas: 32'

Result:

enter image description here

Obs.: I Want to avoid using the <TabItem.Header>, because this creates some problems with my customs templates.

CodePudding user response:

This code is working :

<ListBox Name="lista_etapas">
            <ListBoxItem>A</ListBoxItem>
            <ListBoxItem>B</ListBoxItem>
        </ListBox>
        <TabControl>
            <TabItem  Header="{Binding ElementName=lista_etapas,Path=Items.Count}"  
                      HeaderStringFormat="Etapas: {0}">
            </TabItem>
        </TabControl>

CodePudding user response:

<TabItem  Header="{Binding ElementName=lista_etapas, Path=Items.Count,StringFormat={}Etapas: {0}}">

You need open, close brackets for StringFormat.

  • Related