이 WPF TreeViewItem 스타일이 교차 스레드 문제를 일으키는 이유는 무엇입니까?

두산

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, ItemStructList1 & valueLookupList, DependencyProperty dp, DependencyObject 컨테이너, FrameworkObject 자식, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry & entry, ValueLookupType & sourceType, FrameworkElementFactory templateRoot) at System.Windows.StyleHelper.GetChildValue (UncommonField 1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList1 & childRecordFromChildIndex, EffectiveRootEntry ) at & entry, ValueLookupType & entry, ValueLookupType & entry System.Windows.StyleHelper.GetValueFromTemplatedParent (DependencyObject 컨테이너, Int32 childIndex, FrameworkObject 자식, DependencyProperty dp,FrugalStructList1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
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.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)를 선택합니다.
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) ...

왜 이런 일이 발생하고 해결책은 무엇입니까?

스타일 리소스에서이 세 가지 브러시 재정의를 제거하면 문제가 발생하지 않습니다.

XAMlMAX

스타일의 실제 참조는 element-designer-node-host. 이것은 참조의 소유자를 파괴 된 스레드로 만듭니다. MSDN의 추가 정보 .
이것은 아마도 처음으로 해당 리소스를 사용하는 새 스레드와 관련이있을 수 있지만 더 많은 코드를 보지 않으면 추측에 가깝습니다.
해결책은 WindowUI 스레드 에서 새로 생성되는 것을 만드는 것입니다. 또는 당신이 찾은 것은 x:Shared="false"공유 참조를 사용하는 대신 사용 당 새로 생성 된 참조를 차례로 사용하는 것입니다. 이렇게하면 앱의 메모리 풋 프린트가 증가하고 대상 머신에 사용 가능한 메모리 양이 제한된 경우 메모리 부족 예외가 발생할 수 있습니다.
더 많은 정보MSDN-OutOfMemoryException .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

WPF의 Dispatcher.Invoke가 주 스레드에서 실행될 때 교착 상태를 일으키지 않는 이유는 무엇입니까?

pointfree 스타일이 문제를 일으키지 않는 이유는 무엇입니까?

교차 연결된 defstruct가 스택 오버플로를 일으키는 이유는 무엇입니까?

단일 스레드 실행자를 사용할 때 "header.get () + footer.get ()"이 교착 상태를 일으키는 이유는 무엇입니까?

이 if 문이 이 JS 코드에서 문제를 일으키는 이유는 무엇입니까?

교차 컴파일을 위해 Qt를 소스에서 빌드해야하는 이유는 무엇입니까?

테스트시 ServletServerContainerFactoryBean이 문제를 일으키는 이유는 무엇입니까?

WPF : DataTrigger가 기본 스타일을 삭제하는 이유는 무엇입니까?

이 비동기 / 대기 코드가 교착 상태를 일으키지 않는 이유는 무엇입니까?

WPF 트리거를 스타일 (인라인 포함)로 선언해야하는 이유는 무엇입니까?

pipe.write가 스레드를 차단하는 이유는 무엇입니까?

비 UI 스레드가 UI를 차단하는 이유는 무엇입니까?

Future가 주 스레드를 차단하는 이유는 무엇입니까?

이 커널이 문제를 일으키는 이유는 무엇입니까?

정적 이니셜 라이저에서 람다가있는 병렬 스트림이 교착 상태를 일으키는 이유는 무엇입니까?

이 UserControl이 TreeViewItem.Header를 채울 수없는 이유는 무엇입니까?

C #에서 C ++ 스타일 '친구'키워드를 제공하지 않는 이유는 무엇입니까?

이 캔버스 드로잉이 메모리 누수를 일으키는 이유는 무엇입니까?

파이썬 스레딩. 스레드가 서로를 차단하는 이유는 무엇입니까?

화면이 sftp에 문제를 일으키는 이유는 무엇입니까?

rapidjson이 std :: string에 문제를 일으키는 이유는 무엇입니까?

IE8이 문제를 일으키는 이유는 무엇입니까?

스레드가 JavaFX UI 스레드를 차단하는 이유는 무엇입니까?

레지스터에 할당하는 것이 다른 모든 것에 문제를 일으키지 않는 이유는 무엇입니까?

* {display : *} 스타일이 HTML 본문에 포함 된 이유는 무엇입니까?

이 Future의 방법이 메인 스레드를 차단하는 이유는 무엇입니까?

이 구독이 주 스레드를 차단하는 이유는 무엇입니까?

CornerRadius용 WPF 스타일이 Windows 7에서 적용되지 않는 이유는 무엇입니까?

WPF : 중첩 스타일이 항상 작동하지 않는 이유는 무엇입니까?

TOP 리스트

  1. 1

    Ionic 2 로더가 적시에 표시되지 않음

  2. 2

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  3. 3

    std :: regex의 일관성없는 동작

  4. 4

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  5. 5

    java.lang.UnsatisfiedLinkError : 지정된 모듈을 찾을 수 없습니다

  6. 6

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  7. 7

    상황에 맞는 메뉴 색상

  8. 8

    SMTPException : 전송 연결에서 데이터를 읽을 수 없음 : net_io_connectionclosed

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    Windows cmd를 통해 Anaconda 환경에서 Python 스크립트 실행

  11. 11

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  12. 12

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  13. 13

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  14. 14

    Cassandra에서 버전이 지정된 계층의 효율적인 모델링

  15. 15

    복사 / 붙여 넣기 비활성화

  16. 16

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  17. 17

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  18. 18

    SQL Server-현명한 데이터 문제 받기

  19. 19

    Seaborn에서 축 제목 숨기기

  20. 20

    ArrayBufferLike의 typescript 정의의 깊은 의미

  21. 21

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

뜨겁다태그

보관