Image opacity, rotation and inclusion

I have five images, when you click one of them, I want it to have full opacity, and the other only half to show that it is selected.

I use MVVM and generally wonder if I am doing this correctly.

I was thinking about passing the name of the image source bound to the property.

<StackLayout Grid.Row="3" Grid.Column="1" Orientation="Horizontal" Spacing="0">
                            <Image Source="{Binding StatusUnresolved}" HorizontalOptions="Center"
                                   VerticalOptions="Center" HeightRequest="40" Opacity="{Binding StatusUnresolvedOpacity}">
                                <Image.GestureRecognizers>
                                    <!--<TapGestureRecognizer Command="{Binding Source={x:Reference this}, Path=OnStatusTappedCommand}" CommandParameter="{Binding StatusUnresolved}" />-->
                                </Image.GestureRecognizers>
                            </Image>
                        </StackLayout>

A list to which the string is subsequently included.

  public List<IssueStatusModel> PossibleStatusValues
        {
            get
            {
                var items = new List<IssueStatusModel>
                {
                    new IssueStatusModel("statusUnresolved.png", IssueStatus.Unresolved),
                    new IssueStatusModel("statusInProgress.png", IssueStatus.InProgress),
                    new IssueStatusModel("statusDone.png", IssueStatus.Done)
                };

                return items;
            }
        }

Property for opacity

       public double StatusDoneOpacity
        {
            get { return statusDoneOpacity; }
            set
            {
                if (statusDoneOpacity != value)
                {
                    statusDoneOpacity = value;
                    NotifyPropertyChanged(nameof(StatusUnresolvedOpacity));
                }
            }
        }

        public string StatusDone
        {
            get { return "statusDone.png"; }
        }

public void OnStatusTapped(string fileName)
        {
                foreach (IssueStatusModel item in StatusValues)
                {
                    if (item.Name != fileName) continue;
                    Issue.Status = item.Status;
                    StatusChecker();
                    return;
                }
            }

    }

Switch statement Change all opacity.

    private void StatusChecker()
            {
                switch (Issue.Status)
                {
                    case IssueStatus.Unresolved:
                        StatusUnresolvedOpacity = 1;
                        StatusInProgressOpacity = 0.5;
                        StatusDoneOpacity = 0.5;
                        StatusText = "Unresolved";
                        break;
                    case IssueStatus.InProgress:
                        StatusUnresolvedOpacity = 0.5;
                        StatusInProgressOpacity = 1;
                        StatusDoneOpacity = 0.5;
                        StatusText = "In Progress";
                        break;
                    case IssueStatus.Done:
                        StatusUnresolvedOpacity = 0.5;
                        StatusInProgressOpacity = 0.5;
                        statusDoneOpacity = 1;
                        StatusText = "Done";
                        break;
                }
            }
+4
source share
1 answer

id, , ImageVm , .. enum State IsSelected. , 1 , , vms

DataTrigger, IsSelected MVVM, Opacity , . , IsSelected vms

DataTrigger IsSelected

<Image Grid.Column="2" Stretch="None">
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Setter Property="Opacity" Value="0.5" />
            <Style.Triggers>
                <DataTrigger Value="True" Binding="{Binding IsSelected}">
                    <Setter Property="Opacity" Value="0.5"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

, . .

, (, ), . .

, .

+2

Source: https://habr.com/ru/post/1694641/


All Articles