Basics in XAML

  • Thread starter Thread starter MeridaHu
  • Start date Start date
M

MeridaHu

Guest
Hola,

I hope i have posted in the right forum. if i'm in the wrong forum, please let me know.

I'm learning to build an App in C#. I'm new to programming in high level languages. So i have a couple of questions here that might seem rudimentary to all of you out there. But i'm hoping i can learn from my mistakes and build on.

1. I used the following website to build a basic App.

docs.microsoft.com/en-us/windows/uwp/get-started/create-a-hello-world-app-xaml-universal

After I completed the App, I added a class to the code "TableData.cs"

namespace HelloWorld
{

class TableData
{
public int[] Row;

public int[] Column;
}
}


I renamed the "Hello World" button to "Create Table".


<Grid>
<Button x:Name="button" Content="Create Table" HorizontalAlignment="Left" Margin="558,402,0,0" VerticalAlignment="Top" RenderTransformOrigin="2.188,1.473" Click="Button_Click"/>
<StackPanel Orientation="Horizontal">
<Button Content ="Add Row" Margin ="300" Click="Button_Click1" />
<Button Content ="Add Column" Margin ="0" Click="Button_Click2" />
</StackPanel>
</Grid>


I also added two other buttons called "Row" and "Column"
i am hoping that when a user clicks on the Create Table button, a random table of 5 rows and 5 columns will be created and initialized with the values 0. For which i added the code to the clickbutton.

private async void Button_Click(object sender, RoutedEventArgs e)
{

List<TableData> TableOne = new List<TableData>();
int[] numbers = { 1, 2, 3, 4, 5 };

for(int i=1; i<numbers.Length;i++)
{
TableOne.Add(new TableData());
TableOne.Column = 0;
TableOne.Row = 0;
}

MediaElement mediaElement = new MediaElement();
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello, World!");
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}


The 'For Loop' in the above snippet is meant to added 5 rows and columns of 0's to the table. But i think my implementation is wrong, because the code quits on me when debugging the second line in the 'for' loop. I want to learn to use Classes & List in this structure, which is why i did the way i did.


2. how can i access the list "Table one" when i jump to the second button. How do i load the Tableone when im in the "Add Row" & "Add Column" button.

thank you.
M

Continue reading...
 
Back
Top