私はXamarin.Formsで非常に新しく、TableViewで選択した項目に選択したインジケータとしてアイコンを表示しようとしていますが、実際には少し失われています...行が選択されているときに、どのように表示およびイメージを表示できますか?
私の問題は、アイコンはリストの各要素に表示され、デフォルトでは非表示に設定され、ユーザーがリストの任意の要素を選択すると表示されます(もちろん選択解除された行のアイコンは非表示になります)。
これを達成するためのヒント?どんなアイデアやヒントも非常に役立つはずです。
は、ここでリストのコードです:
<base:ListView
ItemsSource="{Binding DeliveryMethodList}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
RowHeight="60"
HeightRequest="120"
BackgroundColor="Transparent"
IsPullToRefreshEnabled="false"
SeparatorVisibility="None"
SelectedItem="{Binding SelectedDeliveryMethod}">
<base:ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand">
<base:Image
HeightRequest="{base:PointSize 15}"
WidthRequest="{base:PointSize 15}"
Source="{x:Static res:Images.AcceptIco}"
IsVisible="{Binding IsSelectedDeliveryIconVisible}"
VerticalOptions="Center"
HorizontalOptions="Center"/>
<base:Label
FontSize="{StaticResource FontSizeMedium1}"
Text="{Binding name}"
HorizontalOptions="Center"
VerticalOptions="Start"
TextColor="White"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</base:ListView.ItemTemplate>
</base:ListView>
、ここでの選択と項目ソースへの私のViewModel方法である:
bool _isSelectedDeliveryIconVisible;
public bool IsSelectedDeliveryIconVisible
{
get { return _isSelectedDeliveryIconVisible; }
set { SetProperty(ref _isSelectedDeliveryIconVisible, value); }
}
ObservableCollection<DeliveryMethod> _deliveryMethodList;
public ObservableCollection<DeliveryMethod> DeliveryMethodList
{
get { return _deliveryMethodList; }
set { SetProperty(ref _deliveryMethodList, value); }
}
DeliveryMethod _selectedDeliveryMethod;
public DeliveryMethod SelectedDeliveryMethod
{
get { return _selectedDeliveryMethod; }
set
{
SetProperty(ref _selectedDeliveryMethod, value);
if (_selectedDeliveryMethod != null)
{
IsSelectedDeliveryIconVisible = true;
}
}
}
ベスト!
ここで、IsSelectedDeliveryIconVisibleはありますか?それはVM上のプロパティか、DeliveryMethod上のプロパティですか?リストの各セルはDeliveryMethodのインスタンスにバインドされています。 – Jason
こんにちは@Jason、私はコードを更新しました。 'IsSelectedDeliveryIconVisible'はVM上のプロパティです。 – requenaxii