giulichajari
New member
- Joined
- Nov 6, 2024
- Messages
- 2
- Programming Experience
- 1-3
I have a DataTemplate with a list of "Tareas", which are Task to do, each elements of "Tarea" has a list of Products:
This list of product is shown in a Picker, thats go good:
In this page a have a button wich carries to other contentPage just to scan a qrcode or barcode, and when it obtains the result it is closed and return, an my idea is: when the code is obtained and returning to assignedtaskpage, updating the picker( the product with this barcode shoud be selected):
I had tried with DislpayAlert and the product is shown perfectly, but the Picker si not showing it as the selected product
ModelTarea:
public class Tarea : INotifyPropertyChanged
{
public ObservableCollection<Producto> Productos { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
This list of product is shown in a Picker, thats go good:
AssignedTasksPage.xaml:
<ContentView Padding="10" IsVisible="{Binding IsEnCursoVisible}" >
<CollectionView ItemsSource="{Binding ListaTareasEnCurso}">
<CollectionView.ItemTemplate>
<DataTemplate>
....
<!-- Picker para Selección de Productos -->
<Picker x:Name="productosPicker"
Title="Seleccionar productos"
TitleColor="Black"
FontAttributes="Bold"
BackgroundColor="LightGray"
TextColor="Black"
ItemsSource="{Binding Productos}"
ItemDisplayBinding="{Binding producto}"
SelectedIndexChanged="OnEventIndexChanged"
SelectedItem="{Binding ProductoSeleccionado, Mode=TwoWay}"
/>
...other componenets
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentView>
In this page a have a button wich carries to other contentPage just to scan a qrcode or barcode, and when it obtains the result it is closed and return, an my idea is: when the code is obtained and returning to assignedtaskpage, updating the picker( the product with this barcode shoud be selected):
assignedTasksPage.xaml.cs:
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = _viewModel;
if (!WeakReferenceMessenger.Default.IsRegistered<QrScannedMessage>(this))
{
WeakReferenceMessenger.Default.Register<QrScannedMessage>(this, async (recipient, message) =>
{
string qrTexto = message.Value.qrText;
string idTarea = message.Value.idCliente;
string idT = message.Value.idT;
var tareaSeleccionada = _viewModel.ListaTareasEnCurso.FirstOrDefault(t => t.id == idT);
if (tareaSeleccionada != null)
{
// Buscar el producto cuyo ID coincide con el texto escaneado
var productoEncontrado = tareaSeleccionada.Productos.FirstOrDefault(p => p.codigo.Trim() == qrTexto.Trim());
if (productoEncontrado != null)
{
DisplayAlert("ok", productoEncontrado?.producto, "ok");
_viewModel.ProductoSeleccionado = productoEncontrado;
}
else
{
await Application.Current.MainPage.DisplayAlert("Producto no encontrado", "No se encontró ningún producto con el código escaneado.", "OK");
}
}
});
}
}
I had tried with DislpayAlert and the product is shown perfectly, but the Picker si not showing it as the selected product