Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ContentPresenter only showing first item in list
    text
    copied!<p>I am trying to create a WPF application where I have a StackPanel that shows a list of accounts. There is an Account object in the code behind for each account, stored in a List structure. I want to databind this to my WPF, but I don't want a listbox.</p> <p>Instead, I defined a template for how each account summary should appear. I then want to stack these in a StackPanel and call it a day.</p> <p>The problem is that the Data Binding only takes the first item from the list and that's it. How to I bind it so that this effectively creates a little stacked list of nicely formatted chunks of data?</p> <p>Here is the relevant WPF code:</p> <pre><code>&lt;StackPanel Name="sp_AccountList" Margin="0,0,0,0" VerticalAlignment="Top"&gt; &lt;StackPanel.Resources&gt; &lt;svc:AccountBalanceColorConverter x:Key="accountColorConverter" /&gt; &lt;Style x:Key="AccountSummaryBackgroundGradient" TargetType="{x:Type StackPanel}"&gt; &lt;!-- nice formatting code here --&gt; &lt;/Style&gt; &lt;Style x:Key="AccountSummaryNameStyle" TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Padding" Value="10,0,0,0" /&gt; &lt;Setter Property="FontSize" Value="18" /&gt; &lt;Setter Property="Height" Value="20" /&gt; &lt;Setter Property="FontFamily" Value="Cambria" /&gt; &lt;Setter Property="Foreground" Value="White" /&gt; &lt;Setter Property="Background" Value="Transparent" /&gt; &lt;/Style&gt; &lt;Style x:Key="AccountSummaryBalanceStyle" TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Padding" Value="10,0,0,0" /&gt; &lt;Setter Property="FontSize" Value="14" /&gt; &lt;Setter Property="Height" Value="20" /&gt; &lt;Setter Property="FontFamily" Value="Cambria" /&gt; &lt;Setter Property="Background" Value="Transparent" /&gt; &lt;/Style&gt; &lt;ObjectDataProvider x:Key="accounts" ObjectType="{x:Type svc:AccountService}" MethodName="ListAccounts" /&gt; &lt;DataTemplate x:Key="AccountSummaryLayout"&gt; &lt;StackPanel Orientation="Vertical" Style="{StaticResource AccountSummaryBackgroundGradient}"&gt; &lt;TextBlock Text="{Binding Path=Name}" Style="{StaticResource AccountSummaryNameStyle}" /&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Foreground="{Binding Path=TotalAccountBalance, Converter={StaticResource accountColorConverter} }" Text="{Binding Path=TotalAccountBalance, Mode=OneWay}" Style="{StaticResource AccountSummaryBalanceStyle}" /&gt; &lt;TextBlock Foreground="{Binding Path=AvailableAccountBalance, Converter={StaticResource accountColorConverter} }" Text="{Binding Path=AvailableAccountBalance, Mode=OneWay}" Style="{StaticResource AccountSummaryBalanceStyle}" /&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/StackPanel.Resources&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;ContentPresenter x:Name="AccountSummaryPresenter" ContentTemplate="{StaticResource AccountSummaryLayout}" Content="{DynamicResource accounts}" /&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload