Hello.
I have a Solution that contains 2 Classes.
1- MainWindow (which contains a button and a grid).
2- PO (which contains a textbox and a label).
When the solution is launched the MainWindow is displayed with button and grid.
When the button is clicked PO is launched and appears the the grid of MainWindow.
All works fine with my VB version but when I change it to C# I get errors.
The VB code looks like this.
[code]
Class MainWindow
Private Sub Window_Initialized_1(sender As Object, e As EventArgs)
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
''Add PO to Grid1
Dim content1 As Object
Dim PO As New PO()
Dim PO As New PO()
content1 = PO.Content
PO.Content = Nothing
content1.Name = "hello"
PO.textBox.Text = "hello"
PO.label.Content = "Some Text " & "hello"
PO.Content = Nothing
content1.Name = "hello"
PO.textBox.Text = "hello"
PO.label.Content = "Some Text " & "hello"
Grid1.Children.Add(content1)
End Sub
End Class
[/code] End Sub
End Class
The c# code looks like this.
[code]
public MainWindow()
{
InitializeComponent();
}
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
//'Add PO to Grid1
{
//'Add PO to Grid1
{
object content1 = null;
PO PO = new PO();
content1 = PO.Content;
PO.Content = null;
content1.Name = "hello";
PO.textBox.Text = "hello";
PO.label.Content = "Some Text- " + "hello";
PO.Content = null;
content1.Name = "hello";
PO.textBox.Text = "hello";
PO.label.Content = "Some Text- " + "hello";
Grid1.Children.Add(content1);
}
}
}
}
}
[/code].
What am I doing wrong?
I have included both solution files.
AddWPFWindowToGrid - which is the VB version.
and
AddWPFWindowToGridInC - which is the C# version.
Thank you.
Amit GuptaPosted Jan 18, 2017, 3:43 PM
Tony AllanPosted Jan 18, 2017, 3:04 PM
Amit GuptaPosted Jan 18, 2017, 7:32 AM
Tony AllanPosted Jan 18, 2017, 12:53 AM
Again thank you Amit.
Tony AllanPosted Jan 17, 2017, 5:23 PM
Thank you Amit.
But this then brings up an error in this line.
Amit GuptaPosted Jan 17, 2017, 3:41 PM
Tony AllanPosted Jan 17, 2017, 2:05 PM
The c# code won’t compile (2 errors).
Line “content1.Name = "hello";” has error.
'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Line “Grid1.Children.Add(content1);” has error.
Argument 1: cannot convert from 'object' to 'System.Windows.UIElement'
Afzaal Ahmad ZeeshanPosted Jan 17, 2017, 5:59 AM