Buon Giorno Sto tentando di recuperare la Propieta NegozioId Che è Foreign Key della Tabella Busta per salvare i dati nella tabella busta. Ma Non ci riesco,logicamente i dati della combo sono reperiti dalla Collezione NegozioOser ma poi non so come fare a iniettarli in Busta.NegozioID.
Questo é il Model:
Questo è Il ModelView:codice:[Table("Negozio")]publicpartialclassNegozio { publicNegozio() { Bustas=newHashSet<Busta>(); } [DatabaseGenerated(DatabaseGeneratedOption.None)] publicintNegozioID{get;set;} [Required] [StringLength(10)] publicstringRagioneSociale{get;set;} publicvirtualICollection<Busta>Bustas{get;set;}}
Questa La View:codice:using GalaSoft.MvvmLight;using System.Collections.ObjectModel; using Prova1.Model; using GalaSoft.MvvmLight.CommandWpf; using Prova1.Service; namespace Prova1.ViewModel { /// <summary> /// This class contains properties that the main View can data bind to. /// <para> /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel. /// </para> /// <para> /// You can also use Blend to data bind with the tool's support. /// </para> /// <para> /// See http://www.galasoft.ch/mvvm /// </para> /// </summary> public class MainViewModel : ViewModelBase { /// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> /// IDataAccessService _serviceProxy; ObservableCollection<Busta> _Bustas; public ObservableCollection<Busta> BustaOservable { get { return _Bustas; } set { _Bustas = value; RaisePropertyChanged("BustaOservable"); } } ObservableCollection<Negozio> _Negozios; public ObservableCollection<Negozio> NegozioObser { get { return _Negozios; } set { _Negozios = value; RaisePropertyChanged("Negozio"); } } Busta _Busta; public Busta Busta { get { return _Busta; } set { _Busta = value; RaisePropertyChanged("Busta"); } } Negozio _Negozio; public Negozio Negozio { get { return _Negozio; } set { _Negozio = value; RaisePropertyChanged("Negozio"); } } #region Command Object Declarations public RelayCommand<Busta> SaveCommand { get; set; } #endregion public MainViewModel(IDataAccessService servPxy) { _serviceProxy = servPxy; Busta = new Busta(); Negozio = new Negozio(); SaveCommand = new RelayCommand<Busta>(SalvaBusta); NegozioObser = new ObservableCollection<Negozio>(); } //Metodo Per Salvare La Busta void SalvaBusta(Busta Bus) { Busta.BustaID = _serviceProxy.CreateBusta(Bus); if (Busta.BustaID != 0) { BustaOservable.Add(Busta); RaisePropertyChanged("Busta"); } } //Metodo Per Caricare I dati Della Combobox public void GetNegozio() { foreach (var item in _serviceProxy.GetNegozio()) { NegozioObser.Add(item); } } } }
codice:<Window x:Class="Prova1.View.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding Main,Source={StaticResource Locator}}" Title="MainWindow" Height="429" Width="615" Loaded="Window_Loaded"> <Grid> <TextBox HorizontalAlignment="Left" Height="23" Margin="327,85,0,0" TextWrapping="Wrap" Text="{Binding Busta.BustaID, Mode=TwoWay}" VerticalAlignment="Top" Width="120"/> <Label Content="BustaID" HorizontalAlignment="Left" Margin="238,85,0,0" VerticalAlignment="Top"/> <Label Content="NegozioId" HorizontalAlignment="Left" Margin="238,116,0,0" VerticalAlignment="Top"/> <TextBox HorizontalAlignment="Left" Height="23" Margin="327,142,0,0" TextWrapping="Wrap" Text="{Binding Busta.NomeCliente, Mode=TwoWay}" VerticalAlignment="Top" Width="120"/> <Label Content="NomeCliente" HorizontalAlignment="Left" Margin="238,142,0,0" VerticalAlignment="Top"/> <Button Content="Salva" HorizontalAlignment="Left" Margin="215,233,0,0" VerticalAlignment="Top" Width="75" Command="{Binding SaveCommand}" CommandParameter="{Binding Busta}"/> <ComboBox HorizontalAlignment="Left" Margin="327,116,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding NegozioObser}" SelectedItem="{Binding Negozio}" IsSynchronizedWithCurrentItem="True"> <ComboBox.ItemTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding RagioneSociale}"></TextBlock> </Grid> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> </Grid> </Window>

Rispondi quotando