How to bind a value for a SemanticDescription within a DataTemplate? #369
-
I have items in a CollectionView that I wish to set the semantic description for (so Narrator doesn't say that every element is "Microsoft.Maui.Controls.Platform.ItemTemplateContext") but I can't work out how to bind the value when method only takes a string. I'm sure this is obvious but I can't find any examples or work it out from the docs. Here's what I'm working from: var itemTemplate = new DataTemplate(() => new Border()
{
StrokeShape = new RoundRectangle { CornerRadius = 8, StrokeThickness = 2 },
GestureRecognizers = {
new TapGestureRecognizer().BindCommand(source: ViewModel, path: nameof(ListDetailViewModel.GoToDetailsCommand), parameterPath: "."),
},
Content = new Label().Bind(Label.TextProperty, nameof(SampleItem.Title))
}.SemanticDescription("what goes here?"));
Content = new RefreshView
{
Content = new CollectionView
{
RemainingItemsThreshold = 10,
}.ItemTemplate(itemTemplate)
.Bind(CollectionView.ItemsSourceProperty, nameof(ListDetailViewModel.Items))
.Bind(CollectionView.RemainingItemsThresholdReachedCommandProperty, nameof(ListDetailViewModel.LoadMoreCommand))
}.Bind(RefreshView.IsRefreshingProperty, nameof(ListDetailViewModel.IsRefreshing))
.BindCommand(nameof(ListDetailViewModel.RefreshingCommand)); I need to set the SemanticDescription on the Border to get MAUI to expose the text correctly to the A11Y tooling. Is there a simple way to get that bound value and pass it as a string to the method? Or is there another way to do this entirely? (I looked at creating the Border separately and then trying to set the property, but I still don't see how to set the specific value for the instance in the ItemsSource of the CollectionView.) Related: How to bind attached properties inside a DataTemplate that doesn't have custom extension methods as part of the library? I'm also surprised there's not an easy way within a Template to be able to pass a bound item value to any extension method that accepts a string. Or have I missed that in the docs also? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@TheCodeTraveler @bijington any ideas? |
Beta Was this translation helpful? Give feedback.
You would bind to the BindableProperty in Semantic Description
https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.semanticproperties.descriptionproperty?view=net-maui-9.0