Xamarin表格:单击以禁用状态进入的事件



如何添加处于禁用状态的输入事件?

我尝试了以下手势识别器的尝试:

  <Entry
            TextColor="Black"
            x:Name="phone">
        <Entry.GestureRecognizers>
            <TapGestureRecognizer
                Tapped="StartCall"
                NumberOfTapsRequired="1">
            </TapGestureRecognizer>
        </Entry.GestureRecognizers> 
    </Entry>
 void StartCall(object sender,EventArgs args)
    {
        DisplayAlert("Alert","Hi","ok");
    }

点击入口时在UI上没有警报。

预先感谢

将您的条目放入布局中,并给出示意图的布局。例如

<StackLayout>
    <Entry
        Placeholder="Enter Phone Number"
        IsEnabled="False"
        TextColor="Black"
        x:Name="phone"/>
    <StackLayout.GestureRecognizers>
        <TapGestureRecognizer
            Tapped="StartCall"
            NumberOfTapsRequired="1">
        </TapGestureRecognizer>
    </StackLayout.GestureRecognizers>
</StackLayout>

只需将您的按钮放在处理您的事件

的布局中(例如stacklayout(
<StackLayout>  
    <StackLayout.GestureRecognizers>
            <TapGestureRecognizer
                Tapped="StartCall">
            </TapGestureRecognizer>
    </StackLayout.GestureRecognizers> 
   <!-- InputTransparent="True" to avoid conflicts -->
    <Entry InputTransparent="True"
            TextColor="Black"
            x:Name="phone"/>
<StackLayout> 

@diego rafael souza所说进入专注事件的条目将在用户点击条目

时开火

XAML:

<Entry Placeholder="Phone number" TextColor="Black" x:Name="phone" Focused="StartCall"/>

.cs:

 void StartCall(object sender, EventArgs args){
        DisplayAlert("Alert", "Hi", "ok");
    }

将其放在网格布局中

<Grid>
    <Entry IsEnabled="False" Text="Hello"/>
    <StackLayout>
        <StackLayout.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding EntryTapCommand}" />
        </StackLayout.GestureRecognizers>
    </StackLayout>
</Grid>

最新更新