Hallo zusammen,
vorab möchte ich sagen, dass ich bisher wenig Erfahrung mit WPF habe und diese ganzen Dinge wie Bindings etc. noch lernen muss.
Aber ich habe ein Problem mit einem DataGrid.
Wahrscheinlich ist das relativ einfach für Kenner.
Zur Situation:
Ich möchte in einm Context Menü ein DataGrid darstellen. In der 1. Spalte soll die Bezeichnung (Label) und in der 2. Spalte eine Textbox zur Eingabe enthalten sein.
Ich habe es über folgenden Weg versucht:
Mit diesem Code erhalte ich allerdings folgenden Fehler.
System.ArgumentNullException
Value cannot be null.Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry( TKey key) at System.Collections.Generic.Dictionary`2.TryGetValu e(TKey key, TValue& value) at System.Windows.Controls.DataGridItemAttachedStorag e.TryGetValue(Object item, DependencyProperty property, Object& value) at System.Windows.Controls.DataGridRow.RestoreAttache dItemValue(DependencyObject objectWithProperty, DependencyProperty property) at System.Windows.Controls.DataGridRow.SyncProperties (Boolean forcePrepareCells) at System.Windows.Controls.DataGridRow.PrepareRow(Obj ect item, DataGrid owningDataGrid) at System.Windows.Controls.DataGrid.PrepareContainerF orItemOverride(DependencyObject element, Object item) at System.Windows.Controls.ItemsControl.MS.Internal.C ontrols.IGeneratorHost.PrepareItemContainer(Depend encyObject container, Object item) at System.Windows.Controls.ItemContainerGenerator.Sys tem.Windows.Controls.Primitives.IItemContainerGene rator.PrepareItemContainer(DependencyObject container) at System.Windows.Controls.VirtualizingStackPanel.Ins ertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) at System.Windows.Controls.VirtualizingStackPanel.Add ContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized) at System.Windows.Controls.VirtualizingStackPanel.Mea sureOverride(Size constraint) at System.Windows.Controls.Primitives.DataGridRowsPre senter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint) at System.Windows.Controls.ItemsPresenter.MeasureOver ride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint) at System.Windows.Controls.ScrollContentPresenter.Mea sureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureCellsGroup(Int 32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.ScrollViewer.MeasureOverri de(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Siz e constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Si ze constraint) at System.Windows.Controls.DataGrid.MeasureOverride(S ize availableSize) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Media.VisualBrush.DoLayout(UIElemen t element) at System.Windows.Media.VisualBrush.LayoutCallback(Ob ject arg) at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCat chWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Ich verstehe nicht, warum die DataGrid Füllung so kompliziert ist im Gegensatz zu WinForms. Wenn mir einer von Euch einen Tipp geben könnte wäre ich echt dankbar.
Viele Grüße
feddi
vorab möchte ich sagen, dass ich bisher wenig Erfahrung mit WPF habe und diese ganzen Dinge wie Bindings etc. noch lernen muss.
Aber ich habe ein Problem mit einem DataGrid.
Wahrscheinlich ist das relativ einfach für Kenner.
Zur Situation:
Ich möchte in einm Context Menü ein DataGrid darstellen. In der 1. Spalte soll die Bezeichnung (Label) und in der 2. Spalte eine Textbox zur Eingabe enthalten sein.
Ich habe es über folgenden Weg versucht:
Code:
<MenuItem StaysOpenOnClick="True"> <MenuItem.Header> <DataGrid Name="dg_TimerSettings" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" HeadersVisibility="None"> <DataGrid.Columns> <DataGridTextColumn></DataGridTextColumn> <DataGridTextColumn></DataGridTextColumn> </DataGrid.Columns> <DataGridRow></DataGridRow> <DataGridRow></DataGridRow> <DataGridRow></DataGridRow> <DataGridCell Width="100" Height="25" Grid.Row="0" Grid.Column="0" Content="Hours:" Name="lbl_TimerSettingsHours"></DataGridCell> <DataGridCell Width="100" Height="25" Grid.Row="0" Grid.Column="1" Content="00" Name="txt_TimerSettingsHours"></DataGridCell> </DataGrid> </MenuItem.Header> </MenuItem>
System.ArgumentNullException
Value cannot be null.Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry( TKey key) at System.Collections.Generic.Dictionary`2.TryGetValu e(TKey key, TValue& value) at System.Windows.Controls.DataGridItemAttachedStorag e.TryGetValue(Object item, DependencyProperty property, Object& value) at System.Windows.Controls.DataGridRow.RestoreAttache dItemValue(DependencyObject objectWithProperty, DependencyProperty property) at System.Windows.Controls.DataGridRow.SyncProperties (Boolean forcePrepareCells) at System.Windows.Controls.DataGridRow.PrepareRow(Obj ect item, DataGrid owningDataGrid) at System.Windows.Controls.DataGrid.PrepareContainerF orItemOverride(DependencyObject element, Object item) at System.Windows.Controls.ItemsControl.MS.Internal.C ontrols.IGeneratorHost.PrepareItemContainer(Depend encyObject container, Object item) at System.Windows.Controls.ItemContainerGenerator.Sys tem.Windows.Controls.Primitives.IItemContainerGene rator.PrepareItemContainer(DependencyObject container) at System.Windows.Controls.VirtualizingStackPanel.Ins ertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) at System.Windows.Controls.VirtualizingStackPanel.Add ContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized) at System.Windows.Controls.VirtualizingStackPanel.Mea sureOverride(Size constraint) at System.Windows.Controls.Primitives.DataGridRowsPre senter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint) at System.Windows.Controls.ItemsPresenter.MeasureOver ride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint) at System.Windows.Controls.ScrollContentPresenter.Mea sureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureCellsGroup(Int 32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.ScrollViewer.MeasureOverri de(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Siz e constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Si ze constraint) at System.Windows.Controls.DataGrid.MeasureOverride(S ize availableSize) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Media.VisualBrush.DoLayout(UIElemen t element) at System.Windows.Media.VisualBrush.LayoutCallback(Ob ject arg) at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCat chWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Ich verstehe nicht, warum die DataGrid Füllung so kompliziert ist im Gegensatz zu WinForms. Wenn mir einer von Euch einen Tipp geben könnte wäre ich echt dankbar.
Viele Grüße
feddi
Comment