gpt4 book ai didi

xaml - AutomationProperties.HelpText 不适用于 UWP ListView

转载 作者:行者123 更新时间:2023-12-02 03:25:27 25 4
gpt4 key购买 nike

我有一个像这样的ListView:

<ListView x:Name="ArtistsList"
ItemsSource="{Binding Source={StaticResource ArtistsCVS}}"
SelectionMode="None"
ItemContainerStyle="{StaticResource ListViewContainerStrecher}"
IsItemClickEnabled="True"
ItemClick="ArtistsList_ItemClick">

<ListView.ItemTemplate>
<DataTemplate x:DataType="local:DAPP">
<Grid AutomationProperties.Name="{Binding artist}"
AutomationProperties.HelpText="Navigate to artist info page.">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Image Grid.Column="0"
MaxWidth="60"
Source="{Binding thumb}"
HorizontalAlignment="Center"/>

<Grid Grid.Column="1" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="{Binding artist}"/>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

当我尝试使用“讲述人”时,它会读取艺术家姓名,但不会读取帮助文本。另外,我想知道是否可以将两个值绑定(bind)为 AutomationProperties.Name?

例如,我有一个 ArtistName 和一个 SongName,然后使用 AutomationProperties.Name = "{Binding ArtistName};{Binding SongName}" 然后它会读取类似 Artist (小停顿) SongName 的内容.

最佳答案

When I try to use Narrator it reads the Artist name but it doesn't read help text.

设置AutomationProperties.HelpText attached property DataTemplate 内的内容在这里不起作用。为了解决这个问题,我们可以使用自定义ListView并压倒一切PrepareContainerForItemOverride设置自动化属性的方法。这也是为 ListView 中的项目添加辅助功能支持的推荐方法。

例如:

public class MyList : ListView
{
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
FrameworkElement source = element as FrameworkElement;

source.SetBinding(AutomationProperties.NameProperty, new Binding
{
Path = new PropertyPath("Content.artist"),
RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self }
});

AutomationProperties.SetHelpText(source, "Navigate to artist info page.");
}
}

那么你可以使用MyList代替ListView,并且不需要设置AutomationProperties.NameAutomationProperties.HelpText 不再位于 Grid 中。更多信息请参见XAML accessibility sample .

I want to know is it possible to bind two values a AutomationProperties.Name?

UWP 没有开箱即用的多重绑定(bind)支持。但是,如果 ArtistNamesongName 来自一个模型或 View 模型,那么我们可以使用转换器来实现这一点,如下所示:

public class AutomationPropertiesConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
//Suppose ArtistName and songName are the properties of Song class
var song = (Song)value;

return $"{song?.ArtistName} - {song?.songName}";
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

并使用转换器,如下所示:

public class MyList : ListView
{
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
FrameworkElement source = element as FrameworkElement;

//Suppose Song class is the DataType of the DataTemplate
source.SetBinding(AutomationProperties.NameProperty, new Binding
{
Path = new PropertyPath("Content"),
RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self },
Converter = new AutomationPropertiesConverter()
});

AutomationProperties.SetHelpText(source, "Navigate to artist info page.");
}
}

关于xaml - AutomationProperties.HelpText 不适用于 UWP ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39043795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com