代码之家  ›  专栏  ›  技术社区  ›  DirtyNative

未调用Xamarin.Forms.Mac命令

  •  0
  • DirtyNative  · 技术社区  · 8 年前

    我有一个带有ListView的页面,其中显示了一些包含音频数据的单元格。

    <?xml version="1.0" encoding="UTF-8"?>
    <ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:audioViews="clr-namespace:Lama.Forms.Source.UI.CustomControls.AudioViews;assembly=Lama.Forms"
       x:Class="Lama.Forms.Source.UI.Pages.MainPages.MacOSAudiofileCellView"
       Padding="0" HasShadow="False" >
    
    <StackLayout BackgroundColor="{Binding BackgroundColor}" Orientation="Vertical" Margin="0,2,0,2" Spacing="0">
        <StackLayout.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding SelectCellCommand}" />
        </StackLayout.GestureRecognizers>
    
        <Grid RowSpacing="0" ColumnSpacing="0" VerticalOptions="FillAndExpand" Margin="0,0,0,5">
            <Grid.RowDefinitions>
                <RowDefinition Height="75" />
                <RowDefinition Height="75" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="75" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
    
    ...
    
            <!-- The Playback Buttons -->
            <Grid Grid.Row="1" Grid.Column="1">
    
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
    
                <!-- Play Button -->
                <Image Source="{Binding PlayButtonIcon}">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding PlayCommand}" />
                    </Image.GestureRecognizers>
                </Image>
    
                <!-- Stop Button -->
                <Image Source="{Binding StopButtonIcon}" Grid.Column="1">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding StopCommand}" />
                    </Image.GestureRecognizers>
                </Image>
            </Grid>
    
            <!-- The Grid for Filename, Artist and Title -->
            <Grid Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" RowSpacing="0" ColumnSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
    
                <!-- The Filename -->
                <StackLayout Grid.ColumnSpan="2" Margin="10,0,0,0"
                             Orientation="Horizontal" VerticalOptions="Fill">
    
                    <Label Text="Filename:"
                           VerticalTextAlignment="Center"
                           WidthRequest="100"
                           VerticalOptions="Fill"
                           Style="{StaticResource CellLabel}" />
    
                    <Label x:Name="LblFilename" Text="{Binding Filename}"
                           VerticalTextAlignment="Center"
                           VerticalOptions="Fill"
                           Style="{StaticResource CellLabel}"/>
    
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding ChooseNewFilenameCommand}"/>
                    </StackLayout.GestureRecognizers>
    
                </StackLayout>
    
                <!-- The Artist -->
                <StackLayout Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" Orientation="Horizontal">
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding ChooseNewArtistCommand}"/>
                    </StackLayout.GestureRecognizers>
                    <Label Text="Artist:"
                                   WidthRequest="100"
                                   VerticalTextAlignment="Center" 
                                   Style="{StaticResource CellLabel}"/>
    
                    <Label Text="{Binding Artist}"
                               VerticalTextAlignment="Center"
                               Style="{StaticResource CellLabel}"/>
                </StackLayout>
    
                ...
    </ViewCell>
    

    public class AudiofileCellViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
    
        #region Commands
        public Command SelectCellCommand { get; }
        public Command ChooseNewFilenameCommand { get; }
        public Command ChooseNewArtistCommand { get; }
    
        public Command PlayCommand { get; }
        public Command StopCommand { get; }
        #endregion
    
        #region CTOr
        protected BaseAudiofileCellViewModel()
        {
            SelectCellCommand = new Command(SelectCell);
            ChooseNewFilenameCommand = new Command(async () => await ChooseNewFilename());
            ChooseNewArtistCommand = new Command(ChooseNewArtist);
            ChooseNewTitleCommand = new Command(ChooseNewTitle);
            ChooseNewAlbumCommand = new Command(ChooseNewAlbum);
            ChooseNewCommentCommand = new Command(ChooseNewComment);
            ChooseNewKeyCommand = new Command(ChooseNewKey);
            ChooseNewBpmCommand = new Command(ChooseNewBpm);
    
            PlayCommand = new Command(async () => await PlayAudiofile());
            StopCommand = new Command(StopAllAudiofiles);
        }
        #endregion
    

    有一些为标签定义的命令将在点击时调用。这对Xamarin.Forms.UWP有效,但如果切换到Xamarin.Forms.Mac,它们就不会启动。我可以通过主页上的一个动画视图看到发生了一些事情,它在单击时会结巴,但从来没有断点被击中。 我正在运行最新的稳定:Xamarin.Forms 3.1.0.697729

    1 回复  |  直到 8 年前
        1
  •  0
  •   SushiHangover    8 年前

    根本没有 TapGestureHandler 目前在macOS上的实现,实际上根本没有手势处理程序,因为当前的macOS平台不支持它们。有一个Xamarin写的 NSClickGestureRecognizer

    这在UWP上是有意义的,因为微软不仅在UWP中有触摸界面实现,而且操作系统本身也有触摸界面,如果没有触摸界面,操作系统会将鼠标/触控板的点击转换为“基于触摸的点击”,UWP touch API“刚好”工作。

    现在,未来macOS Mojave将通过苹果将基于iOS的框架移植到macOS,从而支持iOS应用程序 已经移植,您将能够使用UIKit而不仅仅是AppKit。因此,这将支持将这些鼠标/触控板点击转换为本机 UITapGestureRecognizer 事件。我还没有深入到Mojave,看看这将如何做,如果AppKit小部件将继承UIKit的能力,但因为你正在使用 Xamarin.Forms 你只需要等到Xamarin支持新的操作系统功能(当然你的应用程序只会是Mojave,至少在触摸支持方面)。

    推荐文章