如何为处于禁用状态的条目添加click事件?
我尝试使用如下手势识别器:
<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上没有显示任何警告。
提前致谢
答案 0 :(得分:6)
将您的条目放在布局中,并为GestureRecognizers布局。 e.g
<StackLayout>
<Entry
Placeholder="Enter Phone Number"
IsEnabled="False"
TextColor="Black"
x:Name="phone"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="StartCall"
NumberOfTapsRequired="1">
</TapGestureRecognizer>
</StackLayout.GestureRecognizers>
</StackLayout>
答案 1 :(得分:2)
正如@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");
}
答案 2 :(得分:2)
只需将按钮放在处理事件的布局(例如StackLayout)
中<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="StartCall">
</TapGestureRecognizer>
</StackLayout.GestureRecognizers>
<!-- InputTransparent="True" to avoid conflicts -->
<Entry InputTransparent="True"
TextColor="Black"
x:Name="phone"/>
<StackLayout>