Witam , jestem początkującym programistą i wiem że jest tego mnóstwo w internecie , ale jest tego dużo napisane i ciężko mi się połapać . Problem tkwi w bindowaniu danych z 2 do 1 okna a mianowicie listview , zrobiłem 2 apke na 1 txtboxa zeby bylo łatwiej to ogarnąć .
Xaml glowne okno:
<Window x:Class="WpfApplication15.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication15"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Name="btn_dodajokno" Content="Dodaj" Margin="0,288,0,0"></Button>
<ListView Name="lista" Margin="0,0,0,35">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridView.Columns>
<GridViewColumn Width="525" Header="Opis" DisplayMemberBinding="{Binding tekst}"></GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
Window1 :
<Window x:Class="WpfApplication15.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication15"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox Name="txtbox_tekst" Margin="0,0,0,33"></TextBox>
<Button Name="btn_dodaj" Content="Dodaj" Margin="0,240,0,0" Click="btn_dodaj_Click"></Button>
</Grid>
</Window>
Window1 xaml.cs
namespace WpfApplication15
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
private List<Class1> dane = null;
public Window1()
{
InitializeComponent();
}
private void btn_dodaj_Click(object sender, RoutedEventArgs e)
{
dane = new List<Class1>();
dane.Add(new Class1("dasdad"));
// Tutaj powinno byc name listview jako listview.itemsource = dane;
//dlaczego nie widzi listview ?
}
}
}