これは私のxamlコードです:
<TextBox x:Name="name_box_det" Text="{Binding Name}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
これは、テキスト値を取得するための C# コードです。
var name_text_det = name_box_det.Text;
そして、私はこの例外を受けています:
The name 'name_box_det' does not exist in the current context
Xaml コードは別の xaml からコピーされますが、まったく新しいものを記述しようとしましたが、役に立ちません。どこが間違っているか分かりますか?
これは完全な XAML コードです。
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image Margin="0" Grid.Row="1" Source="devdesk.png" Stretch="Fill"/>
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,45,12,12"Orientation="Horizontal">
<ListBox x:Name="listBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Height="27" Margin="0,0,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Record index:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox Text="{Binding Index}" x:Name="index_box_det" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Name="record_name" Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Record name:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="name_box_det" Text="{Binding Name}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Beneficiary:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="beneficiary_box_det" Text="{Binding Beneficiary}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Price:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="price_box_det" Height="65" Text="{Binding Price}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Deadline:" Foreground="#FF6C6C6C"/>
<TextBox x:Name="deadline_box_det" Text="{Binding Deadline}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Description:" Foreground="#FF6C6C6C" Height="27" VerticalAlignment="Bottom"/>
<TextBox x:Name="description_box_det" Text="{Binding Description}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667" Height="285" VerticalAlignment="Bottom"/>
<Button Width="375" x:Name="edtbtn" Content="Edit this record" Click="edtbtn_Click" Height="88" Margin="-12,-10,0,0" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" BorderThickness="3" Foreground="#FF40AA2F" BorderBrush="#FF40AA2F" Background="{x:Null}"/>
<Button Width="100" x:Name="dltbtn" Click="dltbtn_Click" Height="88" Margin="-12,-98,0,0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" BorderThickness="3" Foreground="#FF40AA2F" BorderBrush="#FF40AA2F" Background="{x:Null}">
<StackPanel>
<Image Source="delete.png"/>
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>