When you put a TextBox in a PopupBox and bind the text box to FocusManager.FocusedElement you will get an InvalidOperationException
'ScaleTransform' name cannot be found in the name scope of 'System.Windows.Controls.ControlTemplate'.
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)
No exception and text box is focused when popup is opened.
<PopupBox>
<Grid FocusManager.FocusedElement="{Binding ElementName=MyTextBox}">
<TextBox Name="MyTextBox"/>
</Grid>
</PopupBox>
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:
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?
No repo for this issue yet.
@mgnslndh I am attempting to reproduce this with the following:
<materialDesign:PopupBox StaysOpen="True">
<Grid FocusManager.FocusedElement="{Binding ElementName=MyTextBox}" Width="100">
<TextBox Name="MyTextBox"/>
</Grid>
</materialDesign:PopupBox>
I am not getting the exception, but the text box is not getting focused.
Ok thanks for looking into this! I'll have to see if I can reproduce it in isolation.
@mgnslndh I think this was fixed when I addressed #1104. Can you test with the latest CI package to see if it is resolved (2.5.1-ci1224)?
Closing for now. Let me know if this is still an issue.
using
AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
{
Logger.Instance.Log(LogEventLevel.Error, eventArgs.Exception.ToString());
};
and getting exception
Still getting exceptions too
@ranjan-ranjan a first chance exception notification is not an indication of a problem. Are you seeing an exception actually making it to your application or a crash?
@DaRochaRomain can you provide more information on the exception that you are getting. The code that was causing the original stack trace posted above has been removed.
@Keboo No.
And I may have found the problem. It comes because I have writing to TextBox which is present in a Window that isn't loaded. When I commented the problematic lines. It wasn't giving the exception.
I encountered this problem as well. It would throw an exception if I called myTextbox.Focus() in my MainWindow constructor. Since calling focus before the window is shown is valid, I would think that this should be supported by the toolkit.
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.
I am getting same error, but I am using MaterialDesignThemes 2.5.0.1205 (latest version on NuGet!
I set focus on textbox and if user click button on the same form InvalidOperationException pops up.
EDIT: after manually updating to latest&greatest version 2.5.1-ci1297, IT WORKED! :)
@spiegelp @Keboo
Hello , We had a same issue with version 2.5.0.1205 , But with the new pre - released version it is resolved (2.5.1-ci1284) , could you please let me know when you have planned to release a official version of 2.5.1-ci1284 .
Thanks in advance
@varunfime 2.5.1 was released earlier this week.