2016-06-01 14 views
7

z-indexの概念はありますか? 画像に重複がないことが示されています。 enter image description here Z-indexの設定方法は? 上の2つのカスタム選択ボックスXamarinフォームではどのようにオーバーラップしますか?

<AbsoluteLayout Padding="10,10,10,10" VerticalOptions="FillAndExpand"> 

    <ui:BoxSelector x:Name="selectorExchangs" 
        AbsoluteLayout.LayoutBounds="0,0,0.5,0.3" 
        AbsoluteLayout.LayoutFlags="All" 
        BackgroundColor="Transparent" 
        CommandAfterChanged="{Binding ExchangesAfterChangedCommand}" 
        Items="{Binding ExchangesList}" 
        LabelPath="Name" 
        PanelColor="#f9f9f9" 
        SelectedItem="{Binding SelectedExchange}" 
        SelectorLabel="EXCHANGE" /> 

    <ui:BoxSelector AbsoluteLayout.LayoutBounds="1,0,0.5,0.3" 
        AbsoluteLayout.LayoutFlags="All" 
        BackgroundColor="Transparent" 
        CommandAfterChanged="{Binding TradingPairAfterChangedCommand}" 
        Items="{Binding AvailableTradinPairsList}" 
        LabelPath="PriceCurrencyName" 
        PanelColor="#f9f9f9" 
        SelectedItem="{Binding SelectedTraingPair}" 
        SelectorLabel="CURRENCY" /> 

そしてすべての残りの部分。チャート、データ、e.t.c

<StackLayout AbsoluteLayout.LayoutBounds="1,1,1,0.9" AbsoluteLayout.LayoutFlags="All">...</StackLayout> 

BoxSelector.xaml(コンテンツビュー)は、再利用可能なContentViewは

<ContentView.Resources> 
    <ResourceDictionary x:Name="AppDictionary"> 
     <Color x:Key="BackgroundColor">#f9f9f9</Color> 
     <Color x:Key="BorderColor">#e2e2e2</Color> 
     <Style x:Key="InternalViewStyle" TargetType="ContentView"> 
      <Setter Property="BackgroundColor" Value="{StaticResource BackgroundColor}" /> 
      <Setter Property="VerticalOptions" Value="Fill" /> 
      <Setter Property="Padding" Value="5,5,5,5" /> 
     </Style> 
     <Style x:Key="BorderStyle" TargetType="ContentView"> 
      <Setter Property="BackgroundColor" Value="{StaticResource BorderColor}" /> 
      <Setter Property="Padding" Value="1,1,1,1" /> 
     </Style> 
    </ResourceDictionary> 
</ContentView.Resources> 

<StackLayout BindingContext="{x:Reference Name=ContentView}" HorizontalOptions="FillAndExpand"> 
    <ContentView BackgroundColor="#f5f5f5" HorizontalOptions="FillAndExpand"> 
     <StackLayout> 
      <ContentView Style="{StaticResource BorderStyle}"> 
       <ContentView Style="{StaticResource InternalViewStyle}"> 
        <StackLayout Orientation="Horizontal"> 
         <StackLayout x:Name="selectorBox" 
            BackgroundColor="{Binding PanelColor}" 
            HorizontalOptions="FillAndExpand" 
            Orientation="Horizontal"> 
          <StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal"> 
           <Label FontSize="12" 
             HorizontalOptions="FillAndExpand" 
             Text="{Binding SelectorLabel}" 
             TextColor="#cccccc" /> 
           <Label x:Name="valueLabe" 
             BackgroundColor="{Binding PanelColor}" 
             FontSize="13" 
             HorizontalOptions="FillAndExpand" 
             Text="Choose" 
             TextColor="#313131" /> 
          </StackLayout> 
          <StackLayout HorizontalOptions="EndAndExpand"> 
           <Label Text="+" TextColor="#313131" /> 
          </StackLayout> 
         </StackLayout> 
        </StackLayout> 
       </ContentView> 
      </ContentView> 

      <Grid x:Name="boxSelectorGrid" 
        BackgroundColor="#f5f5f5" 
        Padding="10,10,10,10"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="*" /> 
        <ColumnDefinition Width="*" /> 
       </Grid.ColumnDefinitions> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
       </Grid.RowDefinitions> 
      </Grid> 

     </StackLayout> 
    </ContentView> 
</StackLayout> 
+2

私はあなたの質問を理解できません。画像には重なりがないと言いますが、「重なり合っている」とは、あるものが別のものの上に描かれていることを意味します。下にあるレイヤーを隠そうとしていますか? –

+0

はい、クリック後 – bleggleb

+1

あなたが欠けている唯一の部分は、最上部のレイヤーに不透明な背景があるように見えます - 「」のような要素は、背景色が設定されておらず、デフォルトで透明になっています。だからあなたの "最上層"の要素は、あなたが望む効果を達成するために 'BacgkroundColor ="#f9f9f9 "'だけ必要です。 – Joe

答えて

15

Z-Indexがコンテナ要素内の子要素の順序によって確立されて延びています。最初の子はZスタックの後ろにあり、2番目の子は上に置かれています。

使用しているレイアウトコンテナによって、各子の配置方法が決まります。 StackLayoutは重複を許可しません。 AbsoluteLayoutRelativeLayoutは、重複を簡単に許可します。 Gridは、同じ行と列にまたがる要素のオーバーラップを許可します。これらのどれも、独自の外観を持っていません(デフォルトでは透明なボックスとみなされます)。それらの背後にあるコンテンツを隠す場合は、背景色や画像を割り当てる必要があります。そうでない場合は、他のコンテンツのすぐ上にペイントされます。

+1

XFには何もありませんか? – Shimmy

関連する問題