-
Am I doing something wrong or is this an issue? ContextChanging the state causes the application to crash. I was expecting it to throw here OS: Windows 10 Simple code reproductionPage<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MyTest.Pages.TestPage">
<VerticalStackLayout Padding="15">
<Button Text="ChangeState" Clicked="Button_Clicked" />
<ScrollView x:Name="TestStateContainer">
<toolkit:StateContainer.StateViews>
<Label x:Name="FirstStateView"
toolkit:StateView.StateKey="FirstState"
Text="First State" />
<Label x:Name="SecondStateView"
toolkit:StateView.StateKey="SecondState"
Text="Second State" />
</toolkit:StateContainer.StateViews>
<Label Text="Default State" />
</ScrollView>
</VerticalStackLayout>
</ContentPage> Code behindnamespace MyTest.Pages;
using System.Linq;
using CommunityToolkit.Maui.Layouts;
public partial class TestPage : ContentPage
{
readonly List<string> _arr = new() { "FirstState", "SecondState" };
public TestPage()
{
InitializeComponent();
}
void Button_Clicked(object sender, EventArgs e)
=> ChangeState(
_arr
.Where(x =>
x != StateContainer.GetCurrentState(TestStateContainer)
)
.ElementAt(0)
);
// IRL: I call this from several places, which is why it's a method
void ChangeState(string newState)
{
// Me debugging stuff
var z = StateContainer.GetStateViews(TestStateContainer);
var y = StateContainer.GetCurrentState(TestStateContainer);
// Actual thing
StateContainer.SetCurrentState(TestStateContainer, newState);
// More things IRL
// More debugging
var x = StateContainer.GetCurrentState(TestStateContainer);
var w = StateView.GetStateKey(FirstStateView);
}
} Note: Sorry if it's obvious. I'm new(ish) to MAUI, XAML and the toolkit 😉 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Try changing your StateContainer element to a layout element like
|
Beta Was this translation helpful? Give feedback.
-
Closed as answered |
Beta Was this translation helpful? Give feedback.
Try changing your StateContainer element to a layout element like
VerticalStackLayout
. You can still wrap aScrollView
around it.