[英]ListBox and Isolated Storage
I have two questions about Windows Phone Development: 关于Windows Phone开发,我有两个问题:
I have two ListBox
( ListBox1
, ListBox2
) 我有两个
ListBox
( ListBox1
, ListBox2
)
I save my items in ListBox1
with isolated storage. 我使用隔离存储将项目保存在
ListBox1
。
I want to get the selected item from ListBox1
and put it in the ListBox2
saving in isolated storage2 我想从
ListBox1
获取选定的项目,并将其ListBox2
保存在隔离存储区2中的ListBox2中
When I click on the button to get the selected item in the Listbox1
and put for the ListBox2
my application saves all the items that are in ListBox1
and saves on the Listbox2
. 当我单击按钮以在
Listbox1
获取所选项目并放入ListBox2
我的应用程序将保存ListBox1
所有项目并保存在Listbox2
。
My code: 我的代码:
//Isolated Storage
private IsolatedStorageSettings _ListaCompras;
private IsolatedStorageSettings _ListaComprado;
_ListaCompras = IsolatedStorageSettings.ApplicationSettings;
_ListaComprado = IsolatedStorageSettings.ApplicationSettings;
//Save Item in ListBox1
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBoxProduto.Text != string.Empty)
{
_ListaCompras.Add(textBoxProduto.Text, "Produto");
_ListaCompras.Save();
salvarLista();
contador();
}
else MessageBox.Show("Informe o Produto");
}
//Get the Selected item for ListBox1 and put the ListBox2
private void button3_Click(object sender, RoutedEventArgs e)
{
if ((listBoxComprar.Items.Count <= 0) || (this.listBoxComprar.SelectedIndex == -1))
MessageBox.Show("Selecione um item na lista de pendentes");
else
{
_ListaComprado.Add(listBoxComprar.SelectedItem.ToString(), "ProdutoComprado");
_ListaComprado.Save();
salvarLista2();
}
}
//BIND KEYS
public void salvarLista()
{
listBoxComprar.Items.Clear();
foreach (string key in _ListaCompras.Keys)
{
this.listBoxComprar.Items.Add(key);
}
textBoxProduto.Text = "";
}
public void salvarLista2()
{
listBoxComprado.Items.Clear();
foreach (string key2 in _ListaComprado.Keys)
{
this.listBoxComprado.Items.Add(key2);
}
}
The question is not very clear but I think I figured it out. 这个问题不是很清楚,但是我想我已经解决了。 You are saving the value as key and a string as value in the applicationsettings.
您将在应用程序设置中将值另存为键,将字符串另存为值。 This should be the other way around, the string (Produto and ProdutoComprado) as keys and the values as values.
相反,这应该是字符串(Produto和ProdutoComprado)作为键,而值作为值。
I think you have the Add(key, value) statement mixed up. 我认为您混淆了Add(key,value)语句。 msdn
msdn
So 所以
_ListaCompras.Add(textBoxProduto.Text, "Produto");
should be: 应该:
_ListaCompras.Add("Produto", textBoxProduto.Text);
and 和
_ListaComprado.Add(listBoxComprar.SelectedItem.ToString(), "ProdutoComprado");
should be: 应该:
_ListaComprado.Add("ProdutoComprado", listBoxComprar.SelectedItem.ToString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.