I'm trying to make a simple application in UWP for write in a textbox and save it (with a button) into a datagrid...
i don't find how to make this and i really new (noob) using this platform.
this the only i found about this
How to save data from textbox to datagrid in UWP
For your scenario, you could make a string collection and bind it to DataGrid
item source like the following.
CodeBehind
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private ObservableCollection<string> Items = new ObservableCollection<string>();
private void dataGrid_Loaded(object sender, RoutedEventArgs e)
{
dataGrid.ItemsSource = Items;
}
private void SubmitButton_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(ContentTextBox.Text))
{
Items.Add(ContentTextBox.Text);
ContentTextBox.Text = string.Empty;
}
}
}
Xaml Code
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBox x:Name="ContentTextBox" />
<Button
x:Name="SubmitButton"
Grid.Column="1"
HorizontalAlignment="Right"
Click="SubmitButton_Click"
Content="Submit" />
</Grid>
<controls:DataGrid
x:Name="dataGrid"
Grid.Row="1"
Margin="12"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AlternatingRowBackground="Transparent"
AlternatingRowForeground="Gray"
AreRowDetailsFrozen="False"
AreRowGroupHeadersFrozen="True"
AutoGenerateColumns="False"
CanUserReorderColumns="True"
CanUserResizeColumns="True"
CanUserSortColumns="False"
ColumnHeaderHeight="32"
FrozenColumnCount="0"
GridLinesVisibility="None"
HeadersVisibility="Column"
HorizontalScrollBarVisibility="Visible"
IsReadOnly="False"
Loaded="dataGrid_Loaded"
MaxColumnWidth="400"
RowDetailsVisibilityMode="Collapsed"
RowGroupHeaderPropertyNameAlternative="Range"
SelectionMode="Extended"
VerticalScrollBarVisibility="Visible">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn
Binding="{Binding}"
Header="Content"
Tag="text" />
</controls:DataGrid.Columns>
</controls:DataGrid>
</Grid>