我一直在努力解決這個問題,並且Google很久沒有找到解決方案。我創建了一個SQL表/數據庫,用戶將數據輸入到我創建的輸入字段中,然後按下保存按鈕將其保存到數據庫。然後我在另一個選項卡綁定到我的表的數據網格,但一旦點擊另一個選項卡上的保存按鈕,網格不返回到該選項卡時顯示任何結果,我在這裏做錯了什麼,或者我必須編寫代碼刷新?下面是我的代碼爲數據網格:爲什麼我的數據網格不顯示我的輸入數據?
<DataGrid x:Name="employeeDetailsTableDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="295,160,26,85" RowDetailsVisibilityMode="VisibleWhenSelected" SelectionChanged="employeeDetailsTableDataGrid_SelectionChanged" FontFamily="Arial">
<DataGrid.Columns>
<DataGridTextColumn x:Name="employeeIDColumn" Binding="{Binding EmployeeID}" Header="Employee ID" IsReadOnly="True" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="forenameColumn" Binding="{Binding Forename}" Header="Forename" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="surnameColumn" Binding="{Binding Surname}" Header="Surname" Width="SizeToHeader"/>
<DataGridTemplateColumn x:Name="dOBColumn" Header="DOB" Width="SizeToHeader">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding DOB, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn x:Name="emailAddressColumn" Binding="{Binding EmailAddress}" Header="Email Address" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="countryColumn" Binding="{Binding Country}" Header="Country" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="addressColumn" Binding="{Binding Address}" Header="Address" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="cityColumn" Binding="{Binding City}" Header="City" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="postcodeColumn" Binding="{Binding Postcode}" Header="Postcode" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="skill1Column" Binding="{Binding Skill1}" Header="Skill 1" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="skill2Column" Binding="{Binding Skill2}" Header="Skill 2" Width="SizeToHeader"/>
<DataGridTextColumn x:Name="skill3Column" Binding="{Binding Skill3}" Header="Skill 3" Width="SizeToHeader"/>
<DataGridCheckBoxColumn x:Name="job1Column" Binding="{Binding Job1}" Header="Job 1" Width="SizeToHeader"/>
<DataGridCheckBoxColumn x:Name="job2Column" Binding="{Binding Job2}" Header="Job 2" Width="SizeToHeader"/>
<DataGridCheckBoxColumn x:Name="job3Column" Binding="{Binding Job3}" Header="Job 3" Width="SizeToHeader"/>
<DataGridCheckBoxColumn x:Name="employeeAvailabilityColumn" Binding="{Binding EmployeeAvailability}" Header="Employee Availability" Width="SizeToHeader"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
任何幫助非常感謝,先謝謝您。
你綁定到視圖模型?通常我的'ItemsSource'看起來像這樣:'ItemsSource =「{Binding CollectionName}」' –
哦,那麼我會改變我的表名? –
以前的綁定設置爲:ItemsSource =「{綁定模式= OneWay}」 –