Dalej mi to nie wychodzi......
Mam główne okno MainWindow
kod xaml:
Kopiuj
<Window x:Class="WpfApplication2.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:WpfApplication2"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Frame x:Name="frame" Content="Frame" HorizontalAlignment="Left" Height="150" Margin="40,15,0,0" VerticalAlignment="Top" Width="385"/>
</Grid>
</Window>
C# kod
Kopiuj
namespace WpfApplication2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Uri page1 = new Uri("/page1.xaml", UriKind.Relative);
this.frame.Source = page1;
}
}
}
W nim mam frame gdzie otwiera mi się page1
page1 xaml
Kopiuj
<Page x:Class="WpfApplication2.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApplication2"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1" Height="185" Width="380">
<Grid Background="White">
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="215,50,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<TextBox x:Name="TextBox" HorizontalAlignment="Left" Height="23" Margin="90,50,0,0" TextWrapping="Wrap" Text="{Binding customerNameee}" VerticalAlignment="Top" Width="120"/>
</Grid>
</Page>
kod c# page1
Kopiuj
namespace WpfApplication2
{
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
Window1 win=new Window1();
win.Show();
}
}
}
i po kliknieciu w przycisk otwiera się nam nowe okno z którego wybieramy wiersz i klikamy przycisk wybierz ma się to okno wtedy zamknąć i ma się nam dodac wartość Karol do texboxa w page1.
nowego okna xaml:
Kopiuj
<Window x:Class="WpfApplication2.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:WpfApplication2"
mc:Ignorable="d"
Title="Window1" Height="297" Width="469">
<Grid Height="267" VerticalAlignment="Top" Margin="0,0,0,-1">
<DataGrid x:Name="dataGrid" HorizontalAlignment="Left" VerticalAlignment="Top" Height="195" Width="461">
<DataGrid.Columns>
<DataGridTextColumn Header="nazwa" Binding="{Binding Path=customerName}" Width="80"/>
<DataGridTextColumn Header="nip" Width="80" Binding="{Binding Path=customerNip}" />
<DataGridTextColumn Header="numertelfonu" Width="80" Binding="{Binding Path=customerTelNumber}" />
<DataGridTextColumn Header="email" Width="80" Binding="{Binding Path=customerEmail}" />
</DataGrid.Columns>
</DataGrid>
<Button x:Name="button" Content="wybierz" HorizontalAlignment="Left" Height="60" Margin="195,195,0,-148" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
oraz kod c# Window1
Kopiuj
namespace WpfApplication2
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
{
var row = new Customer
{
customerName = "karol",
customerNip = 12345678910,
customerTelNumber =555555555,
customerEmail = "karo@karo.pl"
};
dataGrid.Items.Add(row);
}
}
private void button_Click(object sender, RoutedEventArgs e)
{
var RowToString = dataGrid.SelectedItem.ToString();
string[] element = RowToString.Split(',');
var klient = new Person {
customerNameee = element[0].ToString(),
customerNippp = element[1].ToString(),
customerTelNumberrr = element[2].ToString(),
customerEmailll = element[3].ToString() };
this.Close();
}
}
}
Klasa customer.cs
Kopiuj
namespace WpfApplication2
{
class Customer
{
public string customerName { get; set; }
public Int64 customerNip { get; set; }
public int customerTelNumber { get; set; }
public string customerEmail { get; set; }
public override string ToString()
{
return $"{customerName},{customerNip},{customerTelNumber},{customerEmail}";
}
}
}
oraz klasa person.cs
Kopiuj
namespace WpfApplication2
{
class Person
{
public string customerNameee { get; set; }
public string customerNippp { get; set; }
public string customerTelNumberrr { get; set; }
public string customerEmailll { get; set; }
}
}
Przy bindowaniu do Datagrida w window1 z obiektu klasy Customer wszytsko działa ale już bindowanie do textboxa z obiektu klasy Person nie działa ........
grzesiek51114Path
w sumie nie jest wymagane :)grzesiek51114