Xamarin表单搜索栏和选择器
我有一个xamarin表单应用程序,我想使用搜索栏控件,在focus上会弹出一个选取器。我是否可以扩展搜索栏以提供此功能?换句话说,我不希望用户在搜索栏框中输入文本,而是从拾取列表中选择文本。任何示例都将不胜感激。当您在元素上调用Focus()时,将显示“选取器”对话框,因此您只需放置一个隐藏的选取器,然后从工具栏项的单击处理程序调用该方法Xamarin表单搜索栏和选择器,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我有一个xamarin表单应用程序,我想使用搜索栏控件,在focus上会弹出一个选取器。我是否可以扩展搜索栏以提供此功能?换句话说,我不希望用户在搜索栏框中输入文本,而是从拾取列表中选择文本。任何示例都将不胜感激。当您在元素上调用Focus()时,将显示“选取器”对话框,因此您只需放置一个隐藏的选取器,然后从工具栏项的单击处理程序调用该方法 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Views.MyPage"
Title="My Page Title"
x:Name="MyPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="ShowPicker" Clicked="ShowPicker">
</ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<DatePicker x:Name="MyPicker" IsVisible="false" />
</ContentPage.Content>
</ContentPage>
namespace MyApp.Views
{
public partial class MyPage : ContentPage
{
public ItemsPage()
{
InitializeComponent();
}
void ShowPicker(object sender, EventArgs e)
{
MyPicker.Focus();
}
}
}
名称空间MyApp.Views
{
公共部分类MyPage:ContentPage
{
公共项目
{
初始化组件();
}
void ShowPicker(对象发送方,事件参数e)
{
MyPicker.Focus();
}
}
}
当您对元素调用Focus()时,将显示“选取器”对话框,因此您只需放置一个隐藏的选取器,然后从工具栏项的单击处理程序中调用该方法
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Views.MyPage"
Title="My Page Title"
x:Name="MyPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="ShowPicker" Clicked="ShowPicker">
</ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<DatePicker x:Name="MyPicker" IsVisible="false" />
</ContentPage.Content>
</ContentPage>
namespace MyApp.Views
{
public partial class MyPage : ContentPage
{
public ItemsPage()
{
InitializeComponent();
}
void ShowPicker(object sender, EventArgs e)
{
MyPicker.Focus();
}
}
}
名称空间MyApp.Views
{
公共部分类MyPage:ContentPage
{
公共项目
{
初始化组件();
}
void ShowPicker(对象发送方,事件参数e)
{
MyPicker.Focus();
}
}
}
您可以查看对Xamarin表单使用XFX控件
在页面顶部添加对以下内容的命名空间引用:
xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls"
然后按如下方式使用控件:
<!-- XfxComboBox-->
<xfx:XfxComboBox
Placeholder="Select make"
SelectedItem="{Binding SelectedVehicleMake}"
Text="{Binding Description}"
ItemsSource="{Binding AssetMakes}"/>
此控件允许绑定到项目源和所选项目,您可以使用Xamarin表单的XFX控件查看 在页面顶部添加对以下内容的命名空间引用:
xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls"
然后按如下方式使用控件:
<!-- XfxComboBox-->
<xfx:XfxComboBox
Placeholder="Select make"
SelectedItem="{Binding SelectedVehicleMake}"
Text="{Binding Description}"
ItemsSource="{Binding AssetMakes}"/>
此控件允许绑定到项源和选定项