Search code examples
c#xamlheaderexpanderwindows-community-toolkit

Multible bindings to a header text.


I am using uwp community toolkits expander and I am having problems bindings multiple values to the header text. Is this even possible ?

 <ListView x:Name="LV"  ItemsSource="{Binding VaccSingelton.VaccOverblikListe}"    ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="LV_SelectionChanged" >

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <controls:Expander x:Name="Expander1"  Margin="0,0,0,10" 
                                              Header="{Binding Name}" IsExpanded="false"  >

                                <Grid Margin="0,10,0,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition></ColumnDefinition>
                                        <ColumnDefinition></ColumnDefinition>
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                    </Grid.RowDefinitions>

                                    <TextBlock FontWeight="Bold" Text="Antal Stik:" Grid.Column="0"></TextBlock>
                                    <TextBlock Text="{Binding Stik}" Grid.Column="1" Margin="10,0,0,0">

                                    </TextBlock>

                                    <TextBlock FontWeight="Bold" Text="Udføres på:" Grid.Column="0" Grid.Row="1"></TextBlock>
                                    <TextBlock Text="{Binding  Udførsel}" Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"></TextBlock>

                                    <TextBlock FontWeight="Bold" Text="Bivirkninger:" Grid.Column="0" Grid.Row="2"></TextBlock>
                                    <TextBlock Text="{Binding  Bivirkninger}" Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"></TextBlock>

                                    <TextBlock FontWeight="Bold" Text="Information:" Grid.Column="0" Grid.Row="3"></TextBlock>
                                    <TextBlock Text="{Binding   Info}" Grid.Column="1" Grid.Row="3" Margin="10,0,0,0"></TextBlock>

                                    <TextBlock FontWeight="Bold" Text="Dato:" Grid.Column="0" Grid.Row="4"></TextBlock>
                                    <TextBlock x:Name="test" Grid.Column="1" Grid.Row="4"  Margin="10,0,0,0">
                                        <Run Text="{Binding OpretVaccDatoText}"></Run>

                                    </TextBlock>

                                </Grid>
                            </controls:Expander>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

Just to make it more clear, I want to add more bindings to the header inside of:

<controls:Expander x:Name="Expander1" Margin="0,0,0,10" Header="{Binding Name}" IsExpanded="false" >

So should possibly look like this:

<controls:Expander x:Name="Expander1" Margin="0,0,0,10" Header="{Binding Name, address, Email}" IsExpanded="false" >


Solution

  • Ideally, I'd recommend just having a property in your viewmodel with what you want to show (I assume the three properties concatenated), but you can also use compiled bindings (x:Bind) for that as it supports functions.

    It does, however, require that your app's minimum target SDK version is 14393 or later!