maui icon indicating copy to clipboard operation
maui copied to clipboard

Exception While setting style in MAUI: The given key 'Microsoft.Maui.Controls.SetterSpecificity' was not present in the dictionary.

Open akshayjain692 opened this issue 1 year ago • 3 comments

Description

Getting exception while changing the style through Data trigger.

<Button Grid.Row="0" Grid.Column="1" Command="{Binding ItemTappedCommand, Source={x:RelativeSource Mode=FindAncestorBindingContext, AncestorType {x:Type ViewModel}}}" CommandParameter="{Binding .}" IsEnabled="{Binding IsCanMoveNext, Source={x:RelativeSource Mode=FindAncestorBindingContext, AncestorType={x:Type ViewModel}}}" FontSize="{StaticResource keyFontSizeSubTitle}" Text="{translator:Translate Key={x:Static TranslationsConstants.csProceed}}"> <Button.Triggers> <DataTrigger Binding="{Binding IsCanMoveNext, Source={x:RelativeSource Mode=FindAncestorBindingContext, AncestorType={x:Type ViewModel}}}" TargetType="Button" Value="True"> <Setter Property="Style" Value="{StaticResource keyCenteredTitlePopUpBackgroundRedButton}" /> </DataTrigger> <DataTrigger Binding="{Binding IsCanMoveNext, Source={x:RelativeSource Mode=FindAncestorBindingContext, AncestorType={x:Type ViewModel}}}" TargetType="Button" Value="False"> <Setter Property="Style" Value="{StaticResource keyDisabledButton}" /> </DataTrigger> </Button.Triggers> </Button>

STACK TRACE : at System.Collections.Generic.SortedList2[[Microsoft.Maui.Controls.SetterSpecificity, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.BindingBase, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_Item(SetterSpecificity key) at Microsoft.Maui.Controls.BindableObject.RemoveBinding(BindableProperty property, BindablePropertyContext context, SetterSpecificity specificity) in //src/Controls/src/Core/BindableObject.cs:line 716 at Microsoft.Maui.Controls.BindableObject.RemoveBinding(BindableProperty property, SetterSpecificity specificity) in //src/Controls/src/Core/BindableObject.cs:line 279 at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, SetterSpecificity specificity) in //src/Controls/src/Core/Setter.cs:line 98 at Microsoft.Maui.Controls.VisualStateManager.VisualStateGroupsPropertyChanged(BindableObject bindable, Object oldValue, Object newValue) in //src/Controls/src/Core/VisualStateManager.cs:line 42 at Microsoft.Maui.Controls.BindableObject.ClearValueCore(BindableProperty property, SetterSpecificity specificity) in //src/Controls/src/Core/BindableObject.cs:line 149 at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, SetterSpecificity specificity) in //src/Controls/src/Core/BindableObject.cs:line 103 at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, SetterSpecificity specificity) in //src/Controls/src/Core/Setter.cs:line 101 at Microsoft.Maui.Controls.Style.UnApplyCore(BindableObject bindable, Style basedOn) in //src/Controls/src/Core/Style.cs:line 191 at Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.UnApply(BindableObject bindable) in //src/Controls/src/Core/Style.cs:line 115 at Microsoft.Maui.Controls.Style.UnApplyCore(BindableObject bindable, Style basedOn) in //src/Controls/src/Core/Style.cs:line 194 at Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.UnApply(BindableObject bindable) in /_/src/Controls/src/Core/Style.cs:line 115 at Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList1 classStyles, IStyle style) in /_/src/Controls/src/Core/MergedStyle.cs:line 190 at Microsoft.Maui.Controls.MergedStyle.set_Style(IStyle value) in /_/src/Controls/src/Core/MergedStyle.cs:line 46 at Microsoft.Maui.Controls.NavigableElement.<>c.<.cctor>b__22_0(BindableObject bindable, Object oldvalue, Object newvalue) in /_/src/Controls/src/Core/Shell/NavigableElement.cs:line 22 at Microsoft.Maui.Controls.BindableObject.ClearValueCore(BindableProperty property, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindableObject.cs:line 149 at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindableObject.cs:line 103 at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, SetterSpecificity specificity) in /_/src/Controls/src/Core/Setter.cs:line 101 at Microsoft.Maui.Controls.TriggerBase.OnConditionChanged(BindableObject bindable, Boolean oldValue, Boolean newValue) in /_/src/Controls/src/Core/Interactivity/TriggerBase.cs:line 117 at Microsoft.Maui.Controls.BindingCondition.OnBoundPropertyChanged(BindableObject bindable, Object oldValue, Object newValue) in /_/src/Controls/src/Core/Interactivity/BindingCondition.cs:line 99 at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in /_/src/Controls/src/Core/BindableObject.cs:line 644 at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindableObject.cs:line 569 at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindingExpression.cs:line 163 at Microsoft.Maui.Controls.BindingExpression.OnElementParentSet(Object sender, EventArgs e) in /_/src/Controls/src/Core/BindingExpression.cs:line 585 at Microsoft.Maui.Controls.Element.OnParentSet() in /_/src/Controls/src/Core/Element/Element.cs:line 625 at Microsoft.Maui.Controls.NavigableElement.OnParentSet() in /_/src/Controls/src/Core/Shell/NavigableElement.cs:line 97 at Microsoft.Maui.Controls.Element.SetParent(Element value) in /_/src/Controls/src/Core/Element/Element.cs:line 430 at Microsoft.Maui.Controls.Element.OnChildRemoved(Element child, Int32 oldLogicalIndex) in /_/src/Controls/src/Core/Element/Element.cs:line 610 at Microsoft.Maui.Controls.VisualElement.OnChildRemoved(Element child, Int32 oldLogicalIndex) in /_/src/Controls/src/Core/VisualElement/VisualElement.cs:line 1270 at Microsoft.Maui.Controls.Element.RemoveLogicalChild(Element element, Int32 index) in /_/src/Controls/src/Core/Element/Element.cs:line 276 at Microsoft.Maui.Controls.Element.RemoveLogicalChild(Element element) in /_/src/Controls/src/Core/Element/Element.cs:line 250 at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index) in /_/src/Controls/src/Core/Layout/Layout.cs:line 282 at Microsoft.Maui.Controls.BindableLayout.RemoveAt(IBindableLayout layout, Int32 index) in /_/src/Controls/src/Core/BindableLayout/BindableLayout.cs:line 180 at Microsoft.Maui.Controls.BindableLayoutController.ClearChildren(IBindableLayout layout) in /_/src/Controls/src/Core/BindableLayout/BindableLayout.cs:line 335 at Microsoft.Maui.Controls.BindableLayoutController.CreateChildren() in /_/src/Controls/src/Core/BindableLayout/BindableLayout.cs:line 316 at Microsoft.Maui.Controls.Internals.NotifyCollectionChangedEventArgsExtensions.Apply(NotifyCollectionChangedEventArgs self, Action3 insert, Action2 removeAt, Action reset) in /_/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs:line 83 at Microsoft.Maui.Controls.BindableLayoutController.ItemsSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in /_/src/Controls/src/Core/BindableLayout/BindableLayout.cs:line 407 at Microsoft.Maui.Controls.WeakNotifyCollectionChangedProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in /_/src/Controls/src/Core/Internals/WeakEventProxy.cs:line 78 at System.Collections.ObjectModel.ObservableCollection1[[FirestopSelector.Features.DinUlGuidedSearch.V1_0_0.Models.OptionItemViewModel, FirestopSelector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection1[[FirestopSelector.Features.DinUlGuidedSearch.V1_0_0.Models.OptionItemViewModel, FirestopSelector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionReset() at System.Collections.ObjectModel.ObservableCollection1[[FirestopSelector.Features.DinUlGuidedSearch.V1_0_0.Models.OptionItemViewModel, FirestopSelector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ClearItems() at System.Collections.ObjectModel.Collection1[[FirestopSelector.Features.DinUlGuidedSearch.V1_0_0.Models.OptionItemViewModel, FirestopSelector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Clear() at FirestopSelector.Features.DinUlGuidedSearch.V1_0_0.DinUlGuidedSearchPageViewModel.ClearItems() in /Users/akshayj/eta/eta/FirestopSelector/Features/DinUlGuidedSearch/V1_0_0/DinUlGuidedSearchPageViewModel.cs:line 606

Steps to Reproduce

  1. Create a Button and attach a data trigger to change the style
  2. As soon as the property change the app crash with exception The given key 'Microsoft.Maui.Controls.SetterSpecificity' was not present in the dictionary.

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.49

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Remove styles to fix the issue

Relevant log output

No response

akshayjain692 avatar Aug 08 '24 10:08 akshayjain692

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Aug 08 '24 10:08 github-actions[bot]

I'm guessing it's related to this https://github.com/dotnet/maui/issues/19762

PureWeen avatar Aug 09 '24 21:08 PureWeen

@akshayjain692 I did not reproduce your problem by verifying https://github.com/dotnet/maui-samples/blob/main/8.0/Fundamentals/TriggersDemos/WorkingWithTriggers/Views/DataTriggerXaml.xaml on the latest 17.12.0 Preview 1.0(8.0.82 & 8.0.80). Could you give us a sample project so we can investigate it further? Looking forward to your reply!

RoiChen001 avatar Aug 16 '24 09:08 RoiChen001

Hi @akshayjain692. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.