KevinBurton

I have a form that is filling in the data first by row then by column. Let me explain. I set the binding as:

Code Block

this.stackPanel1.DataContext = from p in db.PurchaseOrders

from of in p.OrderForms

from li in of.LineItems

where p.TrackingNumber == "1281079"

select new { p, of, li };

My XAML looks like:

Code Block

<Window x:Class="BuySeasonsBrowse.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="293" Width="533">

<Window.Resources>

<DataTemplate x:Key="dt">

<StackPanel>

<TextBox Text="{Binding Path=p.TrackingNumber}"/>

<TextBox Text="{Binding Path=of.OrderSourceId}"/>

<TextBox Text="{Binding Path=li.ProductVariantId}"/>

</< FONT>StackPanel>

</< FONT>DataTemplate>

</< FONT>Window.Resources>

<Grid Height="578">

<Button Height="23" Margin="11,48,0,0" Name="paymentButton" VerticalAlignment="Top" HorizontalAlignment="Left" Width="76" ClickMode="Press" Click="paymentButton_Click">

<Button.BitmapEffect>

<BevelBitmapEffect />

</< FONT>Button.BitmapEffect> Payments

</< FONT>Button>

<Button Height="23" Margin="11,15,0,0" Name="transactionButton" VerticalAlignment="Top" HorizontalAlignment="Left" Width="76" ClickMode="Press" Click="transactionButton_Click">

<Button.BitmapEffect>

<BevelBitmapEffect />

</< FONT>Button.BitmapEffect> Transactions

</< FONT>Button>

<StackPanel Margin="108,26,116,0" Name="stackPanel1" Height="100" VerticalAlignment="Top">

<ListView Name="lv" Height="300" ItemsSource="{Binding}" Width="307">

<ListView.View>

<GridView>

<GridViewColumn Header="Number" CellTemplate="{StaticResource dt}"/>

<GridViewColumn Header="Order Source" CellTemplate="{StaticResource dt}"/>

<GridViewColumn Header="Variant" CellTemplate="{StaticResource dt}"/>

</< FONT>GridView>

</< FONT>ListView.View>

</< FONT>ListView>

<TextBlock>Order Number:</< FONT>TextBlock>

<TextBox Name="textOrderNumber"/>

</< FONT>StackPanel>

</< FONT>Grid>

</< FONT>Window>

But the data is not filled in by column then row it is filled in by row then column. In other words the first row and first column has the data for the tracking number, the second row and first column has the data for the order source, and the third row and the first column has the data for the variant. I was hoping for the data (tracking number, order source, and variant) to be filled in across the columns. This is obviously a very newbie question so sorry. What am I doing wrong While we are at it it would be nice if the view were scrollable and the columns were auto sizing.

Thank you.

Kevin



Re: Windows Presentation Foundation (WPF) Incorrect order for binding.

Varsha Mahadevan - MSFT

I think what you want is to have separate templates for each of the three columns.

<Window x:Class="BuySeasonsBrowse.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="293" Width="533">

<Window.Resources>

<DataTemplate x:Key="dt1">

<StackPanel>

<TextBox Text="{Binding Path=p.TrackingNumber}"/>

</< FONT>StackPanel>

</< FONT>DataTemplate>

<DataTemplate x:Key="dt2">

<StackPanel>

<TextBox Text="{Binding Path=of.OrderSourceId}"/>

</< FONT>StackPanel>

</< FONT>DataTemplate>

<DataTemplate x:Key="dt3">

<StackPanel>

<TextBox Text="{Binding Path=li.ProductVariantId}"/>

</< FONT>StackPanel>

</< FONT>DataTemplate>

</< FONT>Window.Resources>

<Grid Height="578">

<Button Height="23" Margin="11,48,0,0" Name="paymentButton" VerticalAlignment="Top" HorizontalAlignment="Left" Width="76" ClickMode="Press" Click="paymentButton_Click">

<Button.BitmapEffect>

<BevelBitmapEffect />

</< FONT>Button.BitmapEffect> Payments

</< FONT>Button>

<Button Height="23" Margin="11,15,0,0" Name="transactionButton" VerticalAlignment="Top" HorizontalAlignment="Left" Width="76" ClickMode="Press" Click="transactionButton_Click">

<Button.BitmapEffect>

<BevelBitmapEffect />

</< FONT>Button.BitmapEffect> Transactions

</< FONT>Button>

<StackPanel Margin="108,26,116,0" Name="stackPanel1" Height="100" VerticalAlignment="Top">

<ListView Name="lv" Height="300" ItemsSource="{Binding}" Width="307">

<ListView.View>

<GridView>

<GridViewColumn Header="Number" CellTemplate="{StaticResource dt1}"/>

<GridViewColumn Header="Order Source" CellTemplate="{StaticResource dt2}"/>

<GridViewColumn Header="Variant" CellTemplate="{StaticResource dt3}"/>

</< FONT>GridView>

</< FONT>ListView.View>

</< FONT>ListView>

<TextBlock>Order Number:</< FONT>TextBlock>

<TextBox Name="textOrderNumber"/>

</< FONT>StackPanel>

</< FONT>Grid>

</< FONT>Window>