我在texblocknumber.text =“123”中有一个值。当我每按一次按钮时,我想在堆栈中按下该值,然后在列表视图中显示堆栈值。 我在上面的代码中有两个错误 1.我想在stack.Push(texblocknumber.text)中添加texblocknumber.text; 2.我想在列表视图中添加堆栈.push值
<ListBox Margin="0,0,-12,0" x:Name="mylist1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="texblocknumber" Text="{Binding datetime}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<TextBlock x:Name="txt2" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
c#code
static Stack<string> GetStack()
{
Stack<string> stack = new Stack<string>();
stack.Push("fghj");
stack.Push("bnmc");
return stack;
}
答案 0 :(得分:0)
你可以使用按钮的绑定,并使用 Observable collection 作为列表的源代码而不是堆栈,因为它实现了 INotifycollectionchanged 。
答案 1 :(得分:0)
just check this solution what i am doing in it on btn click i am saving content on a observablecollection..and simulataneously i have binded it to listbox..(i am showing with collection of string..you can do it with collection of objects too)..
你列表框..
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding ListOFText}" x:Name="mylist1" VerticalAlignment="Top" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="texblocknumber" Text="{Binding }" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<TextBlock x:Name="txt2" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
你的page.cs ..
public partial class MainPage : PhoneApplicationPage
{
public ObservableCollection<string> ListOFText { get; set; }
public MainPage()
{
InitializeComponent();
ListOFText = new ObservableCollection<string>();
this.DataContext = this;
}
private void Mubutton_Click_1(object sender, RoutedEventArgs e)
{
Button btnObj = sender as Button;
ListOFText.Add(btnObj.Content.ToString());
}
}
希望这可以帮助你..以下查询..评论..