Hello people!
I'm trying to use VisualStateManager for a more consistent state change setup. My problem is, it doesn't seem to be able to recognize components that lie within other containers. Take for instance the following xaml:
<StackLayout x:Name="CMD" Orientation="Horizontal" BackgroundColor="Transparent" Margin="0,0,5,0" IsEnabled="False"> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Disabled"> <VisualState.Setters> <Setter TargetName="icon" Property="Label.TextColor" Value="{DynamicResource colors/disabled}" /> <Setter TargetName="text" Property="Label.TextColor" Value="{DynamicResource colors/disabled}" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid ColumnDefinitions="Auto,Auto,*"> <Label Grid.Column="0" WidthRequest="20" HeightRequest="20" Margin="0,0,10,0" Text="X" x:Name="icon" /> <Label Grid.Column="1" x:Name="text" Text="{Binding AddItemText}" TextColor="{DynamicResource colors/accent}"/> </Grid> </StackLayout>
This is just a representation of the original code, which contains custom controls - but the error is the same:
"InvalidOperationException: 'this element is not in a namescope'"
This only happens when the IsEnabled="False"
property is set in the parent component.
In my real code, the enabled state is set based on a series of conditions, and when trying to set the IsEnabled property in code, I get a NullReferenceException in the Setter... presumably because it can't find the item in question.
Is this a known problem? Is there a solution to this?