【发布时间】:2019-03-31 17:36:26
【问题描述】:
我想创建带有建议的自定义条目控件。在我的应用程序中,我想使用XF.Material library - 我的应用程序需要在 iOS 和 Android 的 Material Design 中。现在我想用库中的材料条目来实现自动完成条目,所以我试图修改Xamarin Custom Controls Autocomplete
它工作正常,但我想在其他控件前面显示 Frame。目前 Frame with items 不是 z-indexed 并且会向下移动其他控件。有什么办法可以实现将其他控件隐藏在框架后面?
- 没有列表的条目
- 带有列表的条目:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:MyApp.Controls"
xmlns:ui="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material.Forms"
x:Class="MyApp.Controls.MaterialAutocomplete">
<ContentView.Content>
<StackLayout Spacing="0">
<ui:MaterialTextField x:Name="MainEntry" TextChanged="SearchText_TextChanged" Focused="SearchText_Focused" Unfocused="SearchText_Unfocused" />
<StackLayout x:Name="SuggestedItemsContainerBottom" IsVisible="false" BackgroundColor="Transparent" Margin="10,-17,10,0">
<Frame x:Name="SuggestedItemsOuterContainer" BackgroundColor="White" HasShadow="false" OutlineColor="Silver" Padding="0">
<controls:RepeaterView x:Name="SuggestedItemsRepeaterView" ShowSeparator="true" SeparatorColor="Silver" SeparatorHeight="1" />
</Frame>
</StackLayout>
</StackLayout>
</ContentView.Content>
</ContentView>
带控件的我的视图:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ui="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material.Forms"
xmlns:controls="clr-namespace:MyApp.Controls"
x:Class="MyApp.Views.AddAddressPage">
<ContentPage.Content>
<ScrollView>
<StackLayout Orientation="Vertical">
<controls:MaterialAutocomplete
BackgroundColor="Transparent"
AlwaysShowUnderline="True"
OpenOnFocus="true"
SearchMember="Value"
SuggestionBorderColor="Silver"
ShowSeparator="true" MaxResults="5" EmptyText="No element found"
SuggestionBackgroundColor="WhiteSmoke"
Placeholder="Miasto"
ItemsSource="{Binding Cities}" SelectedItemCommand="{Binding CitySelectedCommand}">
<controls:MaterialAutocomplete.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="3">
<Label Text="{Binding Value}" TextColor="Black" FontSize="Medium" />
</StackLayout>
</ViewCell>
</DataTemplate>
</controls:MaterialAutocomplete.ItemTemplate>
</controls:MaterialAutocomplete>
<Label Text=" tesst"/>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
-
不确定我是否正确理解了您的问题。你想让“测试”标签留在它的位置吗?这个标签在你的 UI 层次结构中的什么位置?
-
是的,我希望标签保持在初始位置。我已经更新了帖子。添加了带有我的自定义控件和标签的视图 xaml。
标签: forms xamarin layout autocomplete custom-controls