@NiKoTiN1

Как получить доступ к конкретному элементу?

Использовал collection view, где находится DataTemplate. не могу никак сделать вращение конкретного элемента.
Вот код страницы с CollectionView:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="JustEat.news"
             xmlns:local="clr-namespace:JustEat"
             Icon="news1.png"
             x:Name="News">

    <ContentPage.Resources>
        <Style TargetType="CollectionView">
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor"
                                        Value="Transparent" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ContentPage.Resources>

    <CollectionView SelectionMode="Single" x:Name="NVIEW" ItemsSource="{Binding ResepiesItems}" HorizontalOptions="Center" Margin="10" SelectionChanged="NVIEW_SelectionChanged">

        <CollectionView.ItemsLayout>
            <GridItemsLayout Orientation="Vertical"
                             Span="1"
                             HorizontalItemSpacing="20"
                             VerticalItemSpacing="30"/>
        </CollectionView.ItemsLayout>

        <CollectionView.ItemTemplate>
            <DataTemplate>
                <local:NewsViewModel>
                    
                </local:NewsViewModel>

            </DataTemplate>
        </CollectionView.ItemTemplate>

    </CollectionView>
</ContentPage>

И код NewsViewModel:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:local="clr-namespace:JustEat"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="JustEat.NewsViewModel">
  <ContentView.Content>
        <Frame CornerRadius="15" BackgroundColor="#d5dce3" Padding="0" IsClippedToBounds = "True" HasShadow="True" Rotation="{Binding MyRotation}">

            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="570"/>
                    <RowDefinition Height="200"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <local:AspectRatioConteiner AspectRatio="1">

                    <Image Source="{Binding ImageSrc}"
                           Aspect="AspectFill"
                           HorizontalOptions="FillAndExpand"
                           VerticalOptions="FillAndExpand"  
                           HeightRequest="120"
                           WidthRequest="120"
                           Margin="0,0,0,0"
                           BackgroundColor="Red"/>

                </local:AspectRatioConteiner>

                <Label Grid.Column="0"
                           Grid.Row="1"
                           Text="{Binding Name, Mode=TwoWay}"
                           FontAttributes="Bold"
                           HorizontalOptions="CenterAndExpand"
                           VerticalOptions="Start"
                           x:Name="LabelInItm"/>

            </Grid>

        </Frame>
    </ContentView.Content>
</ContentView>
  • Вопрос задан
  • 106 просмотров
Решения вопроса 1
@SZolotov
Asp.net core, MAUI,WPF,Qt, Avalonia
Если я правильно понял, то нужно вращать элемент collectionview по тапу на нём? Если да, то выключаете выбор элементов collectionview, в контроле элемента коллекции добавляете TapGesture. В обработчике тапа вращаете контрол через RotateTo
ЗЫ. NewsViewModel - неправильный нейминг
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы