私の最後の質問https://stackoverflow.com/questions/18568850/binding-in-combobox-xaml-wpfを参照して、 ClientBookKeepingViewModel にプロパティ FirstName を追加します。しかし、今はエラーが発生しました。
ブレークポイントを使用してデバッグすると、View.ShowDialog() からエラーが発生します
私のコードは次のとおりです。
public int InsertClientBooking(int clientID, ClientBookKeepingViewModel k)
{
var client = new ClientBooking();
using (var context = new ProActiveDBEntities())
{
client.ClientBookID = k.ClientBookKeepingID;
client.ClientID = k.ClientID;
client.EmployeeID = k.EmployeeID;
client.WorkType = k.WorkType;
client.DateRecorded = (DateTime)k.DateRecorded;
client.BookingFormCompleted = k.BookingFormCompleted;
client.TimeBudgetCompleted = k.TimeBudgetCompleted;
client.ProposedCompletionDate = (DateTime)k.ProposedCompletionDate;
client.IsCompleted = k.IsCompleted;
client.FirstName = k.FirstName;
context.Clients.First(i => i.ClientID == clientID).ClientBookings.Add(client);
context.SaveChanges();
return clientID;
}
}
private void btnAddBooking_Click(object sender, RoutedEventArgs e)
{
ClientBookingView view = new ClientBookingView();
ClientBookKeepingViewModel book = new ClientBookKeepingViewModel();
book.Client = (ClientViewModel)this.DataContext;
book.Mode = Mode.Add;
view.DataContext = book;
view.ShowDialog();
}
ClientBookingView.Xmal
<ComboBox Grid.Column="1" Grid.Row="1" Name="cbEmployeeName"
ItemsSource="{Binding Source={StaticResource Employee}}"
DisplayMemberPath="FirstName"
SelectedValue="{Binding Path=FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
SelectedValuePath="FirstName"
<CheckBox Grid.Column="1" Grid.Row="5" Name="dpBookingCompleted" Content="Yes"
IsChecked="{Binding BookingFormCompleted, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
/>
<StackPanel Grid.Row="9" Orientation="Horizontal" Grid.ColumnSpan="3" Margin="0,5,20,0" Grid.Column="1">
<Button x:Name="btnUpdate" Width="80" Margin="10" Height="25"
Command="{Binding ShowUpdateCommand}"
Click="btnUpdate_Click">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MetroButton}">
<Setter Property="IsEnabled" Value="False"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Mode}">
<DataTrigger.Value>
<enum:Mode>Add</enum:Mode>
</DataTrigger.Value>
<Setter Property="Content" Value="Add"/>
</DataTrigger>
<DataTrigger Binding="{Binding Mode}">
<DataTrigger.Value>
<enum:Mode>Edit</enum:Mode>
</DataTrigger.Value>
<Setter Property="Content" Value="Save"/>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=cbEmployeeName, Path=(Validation.HasError)}" Value="false"/>
<Condition Binding="{Binding ElementName=cbWorkType, Path=(Validation.HasError)}" Value="false"/>
<Condition Binding="{Binding ElementName=dpDateRecord, Path=(Validation.HasError)}" Value="false"/>
<Condition Binding="{Binding ElementName=dpProposedCompletionDate, Path=(Validation.HasError)}" Value="false"/>
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="True"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button x:Name="btnCancel" Content="Cancel" Margin="10" Width="80" Height="25"
Command="{Binding CancelCommand}"
Click="btnCancel_Click" />
</StackPanel>
ClientBookListView
<ListView Name="lsvClientOwnerTypeList" Height="150" Width="700"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
HorizontalAlignment="Center"
VerticalAlignment="Top"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding ClientBookList}"
SelectedItem="{Binding SelectedClientBook}">
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource RowButtons}"/>
<GridViewColumn Header="Completed" DisplayMemberBinding="{Binding IsCompleted}" />
<GridViewColumn Header="Employee Name" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Header="Work Type" DisplayMemberBinding="{Binding WorkType}" />
<GridViewColumn Header="Date Recorded" DisplayMemberBinding="{Binding DateRecorded, StringFormat={}\{0:dd/MM/yyyy\}}" />
<GridViewColumn Header="Booking Form Completed" DisplayMemberBinding="{Binding BookingFormCompleted}" />
<GridViewColumn Header="Time Budget Completed" DisplayMemberBinding="{Binding TimeBudgetCompleted}" />
<GridViewColumn Header="Proposed Completion Date" DisplayMemberBinding="{Binding ProposedCompletionDate, StringFormat={}\{0:dd/MM/yyyy\}}" />
</GridView>
</ListView.View>
</ListView>