treeviewitem 컨테이너에 다음 스타일을 적용했습니다. 기본적으로 선택 색상을 재정의하는 데 사용됩니다.
<Style x:Key="element-designer-node-host" TargetType="{x:Type TreeViewItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource nav-tvi-sel-bg1}" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="{DynamicResource nav-tvi-sel-bg1}" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="{DynamicResource nav-tvi-sel-bg2}" />
</Style.Resources>
<Setter Property="IsExpanded" Value="{Binding Expanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding Selected, Mode=TwoWay}" />
</Style>
트리보기에 적용 :
<TreeView
ItemContainerStyle="{StaticResource element-designer-node-host}"
ItemsSource="{Binding Nodes}">
이제 새 스레드에서이 트리보기로 창을 시작하면 모든 것이 잘 작동합니다.
해당 창이 닫히면 완전히 새로운 스레드에서 완전히 새로운 창을 시작하고 일부 노드를 클릭하려고하면 예외가 발생합니다.
다른 스레드가이 개체를 소유하고 있기 때문에 호출 스레드가이 개체에 액세스 할 수 없습니다.
System.Windows.Threading.Dispatcher.VerifyAccess ()의 System.Windows.Freezable.System.Windows.ISealable.get_IsSealed ()의 System.Windows.StyleHelper.SealIfSealable (Object value)의 System.Windows.StyleHelper.GetChildValueHelper (UncommonField)
1 dataField, ItemStructList
1 & valueLookupList, DependencyProperty dp, DependencyObject 컨테이너, FrameworkObject 자식, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry & entry, ValueLookupType & sourceType, FrameworkElementFactory templateRoot) at System.Windows.StyleHelper.GetChildValue (UncommonField1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList
1 & childRecordFromChildIndex, EffectiveRootEntry ) at & entry, ValueLookupType & entry, ValueLookupType & entry System.Windows.StyleHelper.GetValueFromTemplatedParent (DependencyObject 컨테이너, Int32 childIndex, FrameworkObject 자식, DependencyProperty dp,FrugalStructList1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
System.Windows.StyleHelper.OnTriggerSourcePropertyInvalidated (Style ownerStyle, FrameworkTemplate frameworkTemplate, DependencyObject container, DependencyProperty dp, DependencyPropertyChangedEventArgs changedArgs, Boolean invalidateOnlyContainer, FrugalStructList`1Indexs & trigger, System.FromChildFrameworkElementWithActions)에서 System.Windows.StyleHelper.OnTriggerSourcePropertyInvalidated의 1 & 종속, Boolean invalidateOnlyContainer) .OnPropertyChanged (DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.NotifyPropertyChange (DependencyPropertyChangedEventArgs args) at System.Windows.DependencyObject.UpdateEffectiveValue (EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEnceWithEnferred, EffectiveValueEntry & newDeferrtry, EffectiveValueEntry & newDeferrtrySystem.Windows.DependencyObject.SetValueCommon (DependencyProperty dp, Object value, PropertyMetadata 메타 데이터, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)의 System.Windows.DependencyObject.SetValue (DependencyProperty)의 Boolean coerceWithCurrentValue, OperationType operationType) ) at System.Windows.Controls.TreeView.ChangeSelection (Object data, TreeViewItem container, Boolean selected) at System.Windows.Controls.TreeViewItem.Select (Boolean selected) at System.Windows.Controls.TreeViewItem.OnGotFocus (RoutedEventArgs e)System.Windows.Controls.TreeView.ChangeSelection (Object data, TreeViewItem container, Boolean selected)의 System.Windows.DependencyObject.SetValue (DependencyProperty dp, Object value)의 OperationType operationType, Boolean isInternal)은 System.Windows.Controls.TreeViewItem에 있습니다. System.Windows.Controls.TreeViewItem.OnGotFocus (RoutedEventArgs e)에서 Select (Boolean selected)를 선택합니다.System.Windows.Controls.TreeView.ChangeSelection (Object data, TreeViewItem container, Boolean selected)의 System.Windows.DependencyObject.SetValue (DependencyProperty dp, Object value)의 OperationType operationType, Boolean isInternal)은 System.Windows.Controls.TreeViewItem에 있습니다. System.Windows.Controls.TreeViewItem.OnGotFocus (RoutedEventArgs e)에서 Select (Boolean selected)를 선택합니다.
at System.Windows.FrameworkElement.GetValueFromTemplatedParent(DependencyProperty dp, EffectiveValueEntry& entry) at System.Windows.FrameworkElement.GetRawValue(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& entry) at System.Windows.FrameworkElement.EvaluateBaseValueCore(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& newEntry) at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue) at System.Windows.StyleHelper.InvalidateDependents(Style ownerStyle, FrameworkTemplate frameworkTemplate, DependencyObject container, DependencyProperty dp, FrugalStructList
System.Windows.UIElement.IsFocused_Changed (DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.OnPropertyChanged (DependencyPropertyChangedEventArgs e) at System.Windows.FrameworkElement.OnPropertyChanged (DependencyPropertyChangedEventArgs e) at System.Windows.Dependency ) at System.Windows.DependencyObject.UpdateEffectiveValue (EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry & newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon (DependencyObject.SetValueCommon (DependencyObject) 메타 데이터, 부울 coerceWithDeferredReference, 부울 coerceWithCurrentValue,System.Windows.DependencyObject.SetValue (DependencyPropertyKey key, Object value)의 OperationType operationType, Boolean isInternal) at System.Windows.Input.FocusManager.OnFocusedElementChanged (DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.OnPropertyChangedEventArgs e) System.Windows.FrameworkElement.OnPropertyChanged (DependencyPropertyChangedEventArgs e)의 System.Windows.DependencyObject.NotifyPropertyChange (DependencyPropertyChangedEventArgs args)의 System.Windows.DependencyObject.UpdateEffectiveValue (EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata, EffectiveValueEntry 및 PropertyMetadata, EffectiveValueEntry newWithEntry, EffectiveValueEntry , Boolean coerceWithCurrentValue, OperationType operationType)이 System.Windows.DependencyObject에 있습니다.System.Windows.Input.FocusManager.SetFocusedElement (DependencyObject element, IInputElement value) at System.Windows.Input.KeyboardNavigation.UpdateFocusedElement의 SetValueCommon (DependencyProperty dp, Object value, PropertyMetadata 메타 데이터, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) (DependencyObject focusTarget) at System.Windows.FrameworkElement.OnGotKeyboardFocus (Object sender, KeyboardFocusChangedEventArgs e) at System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler (Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler (Delegate handler, Object target) ) at System.Windows.RoutedEventHandlerInfo.InvokeHandler (Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.System.Windows.UIElement.RaiseTrustedEvent (RoutedEventArgs args) at System.Windows.UIElement.RaiseEventImpl (DependencyObject sender, RoutedEventArgs args)의 InvokeHandlersImpl (Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEvent (RoutedEventArgs args) System.Windows.Input.InputManager.ProcessInput (InputEventArgs input) at System.Windows.Input.InputManager.ProcessInput (InputEventArgs input) at System.Windows.Input.KeyboardDevice.ChangeFocus (DependencyObject focus, Int32 timestamp) at System.Windows.Input.InputManager.ProcessStagingArea () at System.Windows.Input.InputManager.ProcessStagingArea () at System.Windows.Input.InputManager.ProcessInput .Input.KeyboardDevice.TryChangeFocus (DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed) at System.Windows.Input.KeyboardDevice.Focus (DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)Windows.Input.KeyboardDevice.Focus (IInputElement element) at System.Windows.UIElement.Focus () at System.Windows.Controls.TreeViewItem.OnMouseLeftButtonDown (MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonDownThunk (Object sender, MouseButtonEventArgs e) System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler (Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler (Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler (Object target, RoutedEventArgs routedEventArgs) at System. System.Windows.UIElement.ReRaiseEventAs (DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)의 Windows.EventRoute.InvokeHandlersImpl (Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.OnMouseDownThunk (Object sender,MouseButtonEventArgs e) ...
왜 이런 일이 발생하고 해결책은 무엇입니까?
스타일 리소스에서이 세 가지 브러시 재정의를 제거하면 문제가 발생하지 않습니다.
스타일의 실제 참조는 element-designer-node-host
. 이것은 참조의 소유자를 파괴 된 스레드로 만듭니다. MSDN의 추가 정보 .
이것은 아마도 처음으로 해당 리소스를 사용하는 새 스레드와 관련이있을 수 있지만 더 많은 코드를 보지 않으면 추측에 가깝습니다.
해결책은 Window
UI 스레드 에서 새로 생성되는 것을 만드는 것입니다. 또는 당신이 찾은 것은 x:Shared="false"
공유 참조를 사용하는 대신 사용 당 새로 생성 된 참조를 차례로 사용하는 것입니다. 이렇게하면 앱의 메모리 풋 프린트가 증가하고 대상 머신에 사용 가능한 메모리 양이 제한된 경우 메모리 부족 예외가 발생할 수 있습니다.
더 많은 정보MSDN-OutOfMemoryException .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다