我正在尝试在列表视图中动态创建一个文本框和一个按钮,并且效果很好。我尝试的下一件事是获取动态创建的文本框中的文本,并在 button_click 事件上显示为按钮的内容。我很困惑,不知道如何在后面的代码中访问动态创建的按钮或文本“名称属性”对此无效。
欢迎任何建议......
XAML
<ListView Height="222" HorizontalAlignment="Left" Margin="341,24,0,0" Name="listView1" VerticalAlignment="Top" Width="290" Background="Green"
AllowDrop="True"
DragDrop.Drop="listview_drop"
DragDrop.DragEnter="treeview_dragenter" ItemsSource="{Binding XPath=self::*}"></pre>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" x:Name="stc">
<TextBlock Text="{Binding Path=Name}" Margin="0,0,3,0"/>
<ComboBox Margin="0,0,3,0" x:Name="cbox1">
<ComboBoxItem Content="Less Than"/>
<ComboBoxItem Content="Greater Than"/>
<ComboBoxItem Content="Equals"/>
</ComboBox>
<TextBox Margin="0,0,3,0" Width="50" x:Name="textbox1" />
<Button x:Name="but1" Height="25" Width="35" Click="click" Content="gen" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
代码
private void click(object sender, RoutedEventArgs e)
{
//Don`t know what do do here
}