Hello,
When I run following code in a window the binding works normally. But when I do the same thing but make it a usercontrol it stops working.
I've tried so many things but I'm very very new to WPF and in need of help.
Please help ;-) !
window.xaml
<Window x:Class="testwpfgrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding RelativeSource={RelativeSource Self}}"><StackPanel><ListView Name="lv" ItemsSource="{Binding Path=AvosEntries}" IsSynchronizedWithCurrentItem="True"><ListView.View><GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Avos Information"><GridViewColumn DisplayMemberBinding="{Binding Path=AvosName}" Header="Avos Name" Width="100"/></GridView></ListView.View></ListView><Button HorizontalAlignment="Right" Margin="5,5,5,5" Content="Add Row" Click="AddRow_Click" /></StackPanel></Window>window.xaml.cs
public partial class MainWindow : Window
{
public class AvosEntry
{
public string AvosName { get; set; }
}
public MainWindow()
{
AvosEntries = new ObservableCollection<AvosEntry>();
fillList();
InitializeComponent();
}
private void AddRow_Click(object sender, RoutedEventArgs e)
{
AvosEntries.Add(new AvosEntry
{
AvosName = "New Avos Entry"
});
}
private void fillList()
{
for (int i = 1; i <= 10; i++)
{
AvosEntry avosEntry = new AvosEntry();
avosEntry.AvosName = "Avos " + i;
AvosEntries.Add(avosEntry);
}
}
public ObservableCollection<AvosEntry> AvosEntries { get; private set; }
}if i do the same thing but make some changes to it so it is a UserControl instead of a Window (and load the usercontrol into another application and display it, I get a different result... (the object.toSting() is displayed as the value in the cells))
Kind Regards!