Я использую EntityFramework
и работаю над приложением для выставления счетов.Ниже приведен код xaml из моего DataGrid
.Теперь он компилируется и все работает отлично, но проблема в том, что статическая привязка, которую я имею на DataGridComboBoxColumn
, вызывает исключение в режиме конструктора, потому что это статическое свойство фактически загружается из базы данных MySql
с использованием инфраструктуры сущностей.
<DataGrid x:Name="ItemsGrid" Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding Items}" FontSize="11" AutoGenerateColumns="False" CanUserAddRows="False" RowHeaderWidth="0" GridLinesVisibility="None" CanUserResizeRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Width="150" Header="Item No.">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Width="130" BorderThickness="0" Background="Transparent" Text="{Binding Number}" />
<Image MouseDown="ItemSelectionButton_Click" Margin="0,0,0,0" Width="12" Source="/Images/Icons/SearchBlack.png" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="70" Header="Quantity" Binding="{Binding Quantity}" />
<DataGridTextColumn Width="70" Header="Order" Binding="{Binding Order}" />
<DataGridTextColumn Width="70" Header="B/O" Binding="{Binding BackOrder}" />
<DataGridTextColumn Width="60" Header="Units" Binding="{Binding Units}" />
<DataGridTextColumn Width="200" Header="Description" Binding="{Binding Description}" />
<DataGridTextColumn Width="90" Header="Price" Binding="{Binding Price}" />
<DataGridComboBoxColumn Width="50" Header="Tax" ItemsSource="{x:Static app:Session.TaxCodes}" SelectedValueBinding="{Binding TaxCodeID}" DisplayMemberPath="Code" SelectedValuePath="ID" />
<DataGridTextColumn Width="90" Header="Amount" Binding="{Binding Amount}" />
<DataGridTextColumn Width="90" Header="Linked" Binding="{Binding SalesOrderID}" />
</DataGrid.Columns>
</DataGrid>
Вот исключение:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
at DtcInvoicer.Models.DatabaseEntities..ctor() in F:\Development\DTC Industrial\DtcInvoicer\DtcInvoicer\Models\DatabaseModel.Designer.cs:line 42
at DtcInvoicer.Models.Repository.get_GetContext() in F:\Development\DTC Industrial\DtcInvoicer\DtcInvoicer\Models\Repository.cs:line 14
at DtcInvoicer.Models.TaxCodesRepository.SelectAll() in F:\Development\DTC Industrial\DtcInvoicer\DtcInvoicer\Models\TaxCodesRepository.cs:line 54
at DtcInvoicer.Session..cctor() in F:\Development\DTC Industrial\DtcInvoicer\DtcInvoicer\Session.cs:line 18
Я знаю, что попытка устранить корень проблемы будет слишком большой работой, мне интересно, есть ли простой обходной путь, такой как динамическое связывание со статическимнедвижимость в другом классе.У кого-нибудь есть идеи, как это сделать?В поисках решения xaml
.
Вот что я уже пробовал ...
ItemsSource="{Binding Path=TaxCodes, Source={x:Static app:Session}}"
ItemsSource="{Binding Path=TaxCodes, Source={StaticResource app:Session}}"
ItemsSource="{Binding app:Session.TaxCodes}"
Любая помощь приветствуется.
Спасибо.