Hi
also ich bin ratlos. Ich möchte einem UserControl, welches in Xaml(in dem HauptWidow) "erzeugt" wird ein Property mitgeben. Also habe ich ein dependencyProperty hinzugefügt. Was er an das DependencyProperty binden soll: Ein Property aus dem DataContext in dem "HaupWindow". Das Property bleibt aber Null
Hier mal ein wenig code
Spoiler anzeigen
Hier mal was mir VS ausgibt:
Spoiler anzeigen
Was funktioniert ist:
Spoiler anzeigen
Dies kann aber nicht die Lösung sein, da das Parent des UserControls immer etwas anderes sein kann
also ich bin ratlos. Ich möchte einem UserControl, welches in Xaml(in dem HauptWidow) "erzeugt" wird ein Property mitgeben. Also habe ich ein dependencyProperty hinzugefügt. Was er an das DependencyProperty binden soll: Ein Property aus dem DataContext in dem "HaupWindow". Das Property bleibt aber Null
Hier mal ein wenig code
Quellcode
- Public Shared DatenErfassungProperty As DependencyProperty = DependencyProperty.Register("DatenErfassung", GetType(Daten_Erfassung), GetType(ClickAndMove))
- Public Property DatenErfassung As Daten_Erfassung
- Get
- Return _Daten_Erfassung
- End Get
- Set(value As Daten_Erfassung)
- _Daten_Erfassung = value
- End Set
- End Property
Hier mal was mir VS ausgibt:
System.Windows.Data Warning: 56 : Created BindingExpression (hash=26391766) for Binding (hash=53941667)
System.Windows.Data Warning: 58 : Path: 'DataContext.Daten_ErfassungProperty'
System.Windows.Data Warning: 60 : BindingExpression (hash=26391766): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=26391766): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=26391766): Attach to MyoDat.ClickAndMove.DatenErfassung (hash=25759335)
System.Windows.Data Warning: 67 : BindingExpression (hash=26391766): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=26391766): Found data context element: <null> (OK)
System.Windows.Data Warning: 74 : Lookup name HauptWindow: queried TabItem (hash=32377341)
System.Windows.Data Warning: 78 : BindingExpression (hash=26391766): Activate with root item Window2 (hash=57110959)
System.Windows.Data Warning: 108 : BindingExpression (hash=26391766): At level 0 - for Window2.DataContext found accessor DependencyProperty(DataContext)
System.Windows.Data Warning: 104 : BindingExpression (hash=26391766): Replace item at level 0 with Window2 (hash=57110959), using accessor DependencyProperty(DataContext)
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 0 from Window2 (hash=57110959) using DependencyProperty(DataContext): <null>
System.Windows.Data Warning: 106 : BindingExpression (hash=26391766): Item at level 1 is null - no accessor
System.Windows.Data Warning: 80 : BindingExpression (hash=26391766): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 88 : BindingExpression (hash=26391766): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 89 : BindingExpression (hash=26391766): TransferValue - using final value <null>
System.Windows.Data Warning: 96 : BindingExpression (hash=26391766): Got PropertyChanged event from Window2 (hash=57110959) for DataContext
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 0 from Window2 (hash=57110959) using DependencyProperty(DataContext): MainViewModel (hash=23519281)
System.Windows.Data Warning: 108 : BindingExpression (hash=26391766): At level 1 - for MainViewModel.Daten_ErfassungProperty found accessor RuntimePropertyInfo(Daten_ErfassungProperty)
System.Windows.Data Warning: 104 : BindingExpression (hash=26391766): Replace item at level 1 with MainViewModel (hash=23519281), using accessor RuntimePropertyInfo(Daten_ErfassungProperty)
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 1 from MainViewModel (hash=23519281) using RuntimePropertyInfo(Daten_ErfassungProperty): Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 80 : BindingExpression (hash=26391766): TransferValue - got raw value Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 82 : BindingExpression (hash=26391766): TransferValue - user's converter produced Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 89 : BindingExpression (hash=26391766): TransferValue - using final value Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 58 : Path: 'DataContext.Daten_ErfassungProperty'
System.Windows.Data Warning: 60 : BindingExpression (hash=26391766): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=26391766): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=26391766): Attach to MyoDat.ClickAndMove.DatenErfassung (hash=25759335)
System.Windows.Data Warning: 67 : BindingExpression (hash=26391766): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=26391766): Found data context element: <null> (OK)
System.Windows.Data Warning: 74 : Lookup name HauptWindow: queried TabItem (hash=32377341)
System.Windows.Data Warning: 78 : BindingExpression (hash=26391766): Activate with root item Window2 (hash=57110959)
System.Windows.Data Warning: 108 : BindingExpression (hash=26391766): At level 0 - for Window2.DataContext found accessor DependencyProperty(DataContext)
System.Windows.Data Warning: 104 : BindingExpression (hash=26391766): Replace item at level 0 with Window2 (hash=57110959), using accessor DependencyProperty(DataContext)
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 0 from Window2 (hash=57110959) using DependencyProperty(DataContext): <null>
System.Windows.Data Warning: 106 : BindingExpression (hash=26391766): Item at level 1 is null - no accessor
System.Windows.Data Warning: 80 : BindingExpression (hash=26391766): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 88 : BindingExpression (hash=26391766): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 89 : BindingExpression (hash=26391766): TransferValue - using final value <null>
System.Windows.Data Warning: 96 : BindingExpression (hash=26391766): Got PropertyChanged event from Window2 (hash=57110959) for DataContext
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 0 from Window2 (hash=57110959) using DependencyProperty(DataContext): MainViewModel (hash=23519281)
System.Windows.Data Warning: 108 : BindingExpression (hash=26391766): At level 1 - for MainViewModel.Daten_ErfassungProperty found accessor RuntimePropertyInfo(Daten_ErfassungProperty)
System.Windows.Data Warning: 104 : BindingExpression (hash=26391766): Replace item at level 1 with MainViewModel (hash=23519281), using accessor RuntimePropertyInfo(Daten_ErfassungProperty)
System.Windows.Data Warning: 101 : BindingExpression (hash=26391766): GetValue at level 1 from MainViewModel (hash=23519281) using RuntimePropertyInfo(Daten_ErfassungProperty): Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 80 : BindingExpression (hash=26391766): TransferValue - got raw value Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 82 : BindingExpression (hash=26391766): TransferValue - user's converter produced Daten_Erfassung (hash=5588369)
System.Windows.Data Warning: 89 : BindingExpression (hash=26391766): TransferValue - using final value Daten_Erfassung (hash=5588369)
Was funktioniert ist:
Private Sub ClickAndMove_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
_Daten_Erfassung = DirectCast(Me.Parent, TabItem).DataContext.Daten_ErfassungProperty
End Sub
_Daten_Erfassung = DirectCast(Me.Parent, TabItem).DataContext.Daten_ErfassungProperty
End Sub
Dies kann aber nicht die Lösung sein, da das Parent des UserControls immer etwas anderes sein kann