Как получить значение всех элементов ItemsControl WPF
Возникла проблема, имеются множество TextBox-ов, в которых есть значения, все эти TextBox-ы находятся в ItemsControl. Необходимо получить значения всех этих TextBox-ов и передать в функцию из другого класса. Пробовал использовать методы ItemsSource и Items, но при дебаге вижу, что контейнеры null.
XAML код:
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="1">
<ItemsControl x:Name="NFR">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Vertical">
<StackPanel>
<TextBlock Text="ID аккаунта" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="id_account" IsReadOnly="True" Width="200" Height="30" Text="{Binding id_account}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS" Foreground="DimGray">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="ID клиента" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="id_client" IsReadOnly="True" Width="200" Height="30" Text="{Binding id_client}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS" Foreground="DimGray">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel>
<TextBlock Text="Логин" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="login" Width="200" Height="30" Text="{Binding login}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="Пароль" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="password" Width="200" Height="30" Text="{Binding password}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel>
<TextBlock Text="Имя" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="name" Width="200" Height="30" Text="{Binding name_}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="Фамилия" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="second_name" Width="200" Height="30" Text="{Binding second_name}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS" >
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel>
<TextBlock Text="Отчество" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="patronymic" Width="200" Height="30" Text="{Binding patronymic}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0">
<StackPanel>
<TextBlock Text="Дата рождения" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="date_birthday_textbox" Width="200" Height="30" Text="{Binding date_birthday}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="Серия паспорта" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="seria_passport" Width="200" Height="30" Text="{Binding series_passport}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel>
<TextBlock Text="Номер паспорта" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="number_passport" Width="200" Height="30" Text="{Binding number_passport}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="Номер телефона" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="number_phone" Width="200" Height="30" Text="{Binding number_phone}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel>
<TextBlock Text="Электронная почта" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="email" Width="200" Height="30" Text="{Binding email}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
<StackPanel Margin="0,10">
<TextBlock Text="Номер полиса" FontSize="12" FontFamily="Comic Sans MS" Foreground="#498C51"/>
<TextBox x:Name="number_policy" Width="200" Height="30" Text="{Binding number_policy}" Background="{x:Null}" BorderBrush="#498C51" BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="15" FontFamily="Comic Sans MS">
<TextBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</TextBox.Resources>
</TextBox>
</StackPanel>
</StackPanel>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Grid Grid.Row="3" Background="#76E383">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="save" Content="СОХРАНИТЬ" Background="#498C51" Width="130" Height="30" FontSize="15" FontFamily="Comic Sans MS" Margin="0,0,10,0" Click="save_Click" BorderBrush="{x:Null}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Button.Resources>
</Button>
<Button x:Name="back" Content="НАЗАД" Background="#498C51" Width="130" Height="30" FontSize="15" FontFamily="Comic Sans MS" Click="back_Click" IsCancel="True" BorderBrush="{x:Null}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Button.Resources>
</Button>
</StackPanel>
</Grid>
</Grid>
CS код:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Session1.Classes;
namespace Session1.Pages
{
/// <summary>
/// Логика взаимодействия для RedactorClient.xaml
/// </summary>
public partial class RedactorClient : Page
{
bool rewrite;
public RedactorClient(string id, int type_polic)
{
InitializeComponent();
if(id != null)
{
rewrite = true;
NFR.ItemsSource = Load.getDataClient(id);
comboboxPolicy.SelectedIndex = type_polic;
}
else
{
rewrite = false;
}
}
private void back_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new MenuAdministator());
}
private void save_Click(object sender, RoutedEventArgs e)
{
if (rewrite == true)
{
Load.saveClient(NFR.ToString(), true);
}
else
{
Load.saveClient(NFR.ToString(), false);
}
}
}
}
Фоточки дебага:
