Thanks again Arjay. I made some searchs about datatemplates and i tried this before. It works well if i define the listbox or listview inside the window. But if i create my own user control based on listbox or listview and when i create a datatemplate in the user control it only creates one item and binds the first row coming from the database to the template. My usercontrol is like below;
Code:
<ListView x:Class="ControlBinding.LVControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<ListView.ItemTemplate>
<DataTemplate>
<ContentPresenter/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
and in Window.xaml file i use it like;
Code:
<Window x:Class="ControlBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ControlBinding"
Title="Window1" Height="408" Width="562">
<Grid>
<local:LVControl x:Name="LV" Width="Auto" Height="Auto" DataContext="{Binding}" >
<Border Margin="0,0,0,0" CornerRadius="10" BorderThickness="5" BorderBrush="MediumPurple" MaxWidth="400" MaxHeight="250">
<WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<WrapPanel Orientation="Horizontal">
<TextBlock Text="Title:" Width="150"/>
<TextBox Text="{Binding Path=Title}" Width="200"/>
</WrapPanel>
<WrapPanel Orientation="Horizontal">
<TextBlock Text="Name:" Width="150"/>
<TextBox Text="{Binding Path=Name}" Width="200"/>
</WrapPanel>
<WrapPanel Orientation="Horizontal">
<TextBlock Text="Surname:" Width="150"/>
<TextBox Text="{Binding Path=Surname}" Width="200"/>
</WrapPanel>
<WrapPanel Orientation="Horizontal">
<TextBlock Text="Position:" Width="150"/>
<TextBox Text="{Binding Path=Position}" Width="200"/>
</WrapPanel>
</WrapPanel>
</Border>
</local:LVControl>
</Grid>
</Window>
And this results in only one listviewitem and one row. If i change the DataContext="{Binding}" to ItemsSource="{Binding}" it throws Xaml Parse Exception.
What am i doing wrong?
Thanks
Bookmarks