-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why doesn't the Image Indicator Template update its source when the Visual State is set to 'Selected'? #151
Comments
I verified the issue but it seems to be a .NET MAUI problem: |
anyway, this code should work for you too? public class TestModel
{
public string? Title { get; set; }
public string? SubTitle { get; set; }
public string? Description { get; set; }
}
class CarouselTestPageWithImagesState
{
public List<TestModel> Models { get; set; } = new();
public TestModel? SelectedModel { get; set; }
}
class CarouselTestWithImagesPage : Component<CarouselTestPageWithImagesState>
{
private MauiControls.CarouselView? _carouselView;
protected override void OnMounted()
{
State.Models = new List<TestModel>()
{
new TestModel
{
Title = "Lorem Ipsum Dolor Sit Amet",
SubTitle = "Consectetur Adipiscing Elit",
Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in libero non quam accumsan sodales vel vel nunc."
},
new TestModel
{
Title = "Praesent Euismod Tristique",
SubTitle = "Vestibulum Fringilla Egestas",
Description = "Praesent euismod tristique vestibulum. Vivamus vestibulum justo in massa aliquam, id facilisis odio feugiat. Duis euismod massa id elit imperdiet."
},
new TestModel
{
Title = "Aliquam Erat Volutpat",
SubTitle = "Aenean Feugiat In Mollis",
Description = "Aliquam erat volutpat. Aenean feugiat in mollis ac. Nullam eget justo ut orci dictum auctor."
},
new TestModel
{
Title = "Suspendisse Tincidunt",
SubTitle = "Faucibus Ligula Quis",
Description = "Suspendisse tincidunt, arcu eget auctor efficitur, nulla justo tristique neque, et fermentum orci ante eget nunc."
},
};
State.SelectedModel = State.Models.First();
base.OnMounted();
}
public override VisualNode Render()
{
return new ContentPage
{
new VStack
{
new Grid("* 40", "*")
{
new CarouselView(r => _carouselView = r)
.HeightRequest(450)
.HorizontalScrollBarVisibility(ScrollBarVisibility.Never)
.ItemsSource(State.Models, _=> new Grid("*", "*")
{
new VStack
{
new Label(_.Title)
.Margin(0,5),
new Label(_.SubTitle)
.Margin(0,5),
new Label(_.Description)
.Margin(0,8)
}
})
.CurrentItem(() => State.SelectedModel!)
.OnCurrentItemChanged((s, args) => SetState(s => s.SelectedModel = (TestModel)args.CurrentItem))
,
new HStack(spacing: 5)
{
State.Models.Select(item =>
new Image(State.SelectedModel == item ? "tab_home.png" : "tab_map.png")
.WidthRequest(20)
.HeightRequest(20)
.OnTapped(()=>SetState(s=>s.SelectedModel = item, false))
)
}
.HCenter()
.VCenter()
.GridRow(1)
}
}
.Padding(8,0)
.VCenter()
};
}
} |
Yeah. it is the perfect solution. Thanks for the help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to work with
CarouselView
andIndicatorView
using image template.IndicatorTemplate
doesnot change theImage
source when theVisualState
is selected.Simulator.Screen.Recording.-.iPhone.SE.3rd.generation.-.2023-09-08.at.19.24.08.mp4
The text was updated successfully, but these errors were encountered: