Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未调用Xamarin.Forms.Mac命令_C#_Xamarin_Xamarin.forms_Xamarin.forms.listview - Fatal编程技术网

C# 未调用Xamarin.Forms.Mac命令

C# 未调用Xamarin.Forms.Mac命令,c#,xamarin,xamarin.forms,xamarin.forms.listview,C#,Xamarin,Xamarin.forms,Xamarin.forms.listview,我有一个带有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.So

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

目前macOS上没有
TapGestureHandler
实现,实际上根本没有手势处理程序,因为当前的macOS平台不支持它们。Xamarin编写了一个
NSClickGestureRecognizer
,但它在不同的表单控件以及如何在macOS上实现上存在问题

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


现在,未来macOS Mojave将通过Apple将基于iOS的框架移植到macOS来支持iOS应用程序,因此,UIKit框架已经移植,您将能够使用UIKit而不仅仅是AppKit。因此,这将支持将这些鼠标/轨迹板单击转换为本机
UITapgestureRecognitizer
事件。我还没有深入了解Mojave的实际情况,以了解这将如何实现,以及AppKit小部件是否会继承UIKit功能,但由于您使用的是
Xamarin.Forms
,您只需等待Xamarin支持新的操作系统功能(当然,您的应用程序将仅限于Mojave,至少在触摸支持方面).

这不可能100%正确,因为在代码中的其他位置,我的标签会被分配一个TapGestureRecognizer,并且它们会工作。@DanieldRTYNativeMartin你是对的,首先我的意思是
TapGestureHandler
不是recognizer,因为表单的MacOS代码行中没有本机手势处理程序。第二,有一个自定义的
nsClickGestureRecognitor
正在被用作iOS代码行的替代品(这是大多数MacOS渲染器的实时版本),虽然有些地方还可以,但其他的充其量只是粗略的。。。macOS上的表单标签实际上是一个AppKit.NSTextField,“单击”就可以了。查阅Xamarin.Forms上与此相关的公开问题。就我个人而言,我通过使用自己的自定义渲染器避免了这些问题。@DanielDirtyNativeMartin接下来,我认识一位与我共事的人最终添加了透明按钮作为覆盖层,以使
TapGestureRecognitizer
在macOS上正常工作,我刚刚搜索了一个开放性问题,发现这个解决方案也是针对一个7/8个月的开放性bug(不同的问题,但相同的解决方案)这是一个非常愚蠢的解决方案:“也许我会将我的操作系统更新到Mojave,看看它是否已经在那里工作了。”。但是为什么TapGestureRecognitor对一些标签有效,而对ViewCell内部的标签无效?@DanieldRTYNativeMartin我很想听听这些结果:-。。。我有一个莫哈韦虚拟机并行运行,但没有尝试任何Xamarin。它的形式。。。我一直在测试基于H.Sierra的Xamarin.Mac,以便对一些应用程序进行兼容性测试。
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