【发布时间】:2021-10-26 11:08:55
【问题描述】:
我对 CollectionView 和 VisualStateManager 有疑问。 这是我的收藏视图。我也尝试使用编译绑定。
<CollectionView Grid.Row="1"
ItemSizingStrategy="MeasureAllItems"
ItemsSource="{Binding SizeOptions}"
Margin="0"
SelectionChangedCommand="{Binding SelectionChangedCommand}"
SelectedItem="{Binding SelectedSizeOption}"
SelectionMode="Single">
<CollectionView.Header>
<BoxView VerticalOptions="Start"
HeightRequest="1"
Color="{StaticResource DividerColor}"/>
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="tpViewModels:SizeOption">
<StackLayout IsEnabled="{Binding IsEnabled}">
<StackLayout AutomationId="{Binding Text}"
AutomationProperties.IsInAccessibleTree="True"
HeightRequest="64"
IsEnabled="{Binding IsEnabled}"
Margin="10, 0, 0, 0"
MinimumHeightRequest="64"
Orientation="Horizontal"
Padding="0"
x:Name="Holder">
<Image HeightRequest="20"
IsEnabled="{Binding IsEnabled}"
WidthRequest="20"
x:Name="RadioButtonImage">
</Image>
<Label FontSize="14"
HorizontalOptions="StartAndExpand"
IsEnabled="{Binding IsEnabled}"
Padding="10, 0"
Text="{Binding Text}"
Style="{StaticResource MediumFontFamily}"
VerticalTextAlignment="Center"
x:Name="RadioButtonLabel">
</Label>
</StackLayout>
<BoxView VerticalOptions="Start"
HeightRequest="1"
Color="{StaticResource DividerColor}"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
当我在 DataTemplate 中不使用 DataType 时,IsEnabled = false 完美,我们无法选择列表中的项目。但是当我使用 DataType 时,我可以选择禁用项。 我还想在禁用项目时更改 TextColor、FontAttributes 和 Image.Source。
它只为我设置 VisualStates = Normal 或 Selected,VisualStateManager 不适用于 State = Disabled。 我在第一个 StackLayout 中添加了 VisualStateManager,TargetName 设置为 x:Name of Label 和 Image。
DataTrigger for Label 和 Image 有效,但我可以选择禁用的项目 :(
有人知道为什么吗?
【问题讨论】:
标签: xamarin.forms collectionview datatrigger visualstatemanager