question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when TextBox in PopupBox is bound to FocusManager.FocusedElement

See original GitHub issue

Description

When you put a TextBox in a PopupBox and bind the text box to FocusManager.FocusedElement you will get an InvalidOperationException

Exception Message

'ScaleTransform' name cannot be found in the name scope of 'System.Windows.Controls.ControlTemplate'.

Stack Trace

   at System.Windows.Media.Animation.Storyboard.ResolveTargetName(String targetName, INameScope nameScope, DependencyObject element)
   at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
   at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
   at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer)
   at System.Windows.Media.Animation.BeginStoryboard.Begin(DependencyObject targetObject, INameScope nameScope, Int64 layer)
   at System.Windows.StyleHelper.InvokeEventTriggerActions(FrameworkElement fe, FrameworkContentElement fce, Style ownerStyle, FrameworkTemplate frameworkTemplate, Int32 childIndex, RoutedEvent Event)
   at System.Windows.StyleHelper.ExecuteEventTriggerActionsOnContainer(Object sender, RoutedEventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.FrameworkElement.OnGotFocus(RoutedEventArgs e)
   at 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.Controls.TextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   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(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
   at System.Windows.Input.FocusManager.OnFocusedElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   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.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.Activate(Object item)
   at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
   at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
   at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
   at MS.Internal.Data.DataBindEngine.Run(Object arg)
   at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Expected Behaviour

No exception and text box is focused when popup is opened.

Pseudo XAML

<PopupBox>
    <Grid FocusManager.FocusedElement="{Binding ElementName=MyTextBox}">
        <TextBox Name="MyTextBox"/>
    </Grid>    
</PopupBox>

Analysis

The pseudo XAML worked fine on version 2.4 but fails on version 2.5.

This issue seems related to the commit https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/commit/8010f856bc9f116e4ee01584566dc004837e190e because it introduces a new ScaleTransform:

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/cf4f48b0193329aef8078e3aed38b21352f3b982/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml#L64

The scale transform is animated by GotFocus and LostFocus event triggers: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/cf4f48b0193329aef8078e3aed38b21352f3b982/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml#L245-L270

Perhaps @spiegelp can investigate this issue?

Reproduction Link

No repo for this issue yet.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
BryceBarbaracommented, Dec 20, 2018

Nevermind, it definitely was fixed in 2.5.1. Since I ensured I had the most recent stable version in NuGet, I figured I was using that version. Turns out 2.5.1 is prerelease so I needed to check for that before I saw the right version.

1reaction
mgnslndhcommented, Oct 28, 2018

Ok thanks for looking into this! I’ll have to see if I can reproduce it in isolation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set textbox as focused element
Just give the textbox a name (e.g. "theTextBox') and call theTextBox.Focus() . If you're trying to do this in MVVM with data-binding (and ......
Read more >
FocusManager.FocusedElement Attached Property
Determines whether the element this property is attached to has logical focus. ... The following example shows how to make a Button the...
Read more >
FocusManager Class (System.Windows.Input)
Provides a set of static methods, attached properties, and events for determining and setting focus scopes and for setting the focused element within...
Read more >
UDN Search
the keyboardevent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state of modifier...
Read more >
mozilla-central: changeset 117370: ...
This pref is only read once at startup: // a restart is required to ... Treat contenteditble element as a special text field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found