2017-08-27 77 views
0

我想要從一個按鈕 我的菜單列表中查看列表視圖向下滾動菜單是stacklayout所以我展示裏面並使用改變高度出現在集裝箱堆場佈局它的請求,工作正常,但我有一個問題,如果想入手隱藏菜單我的問題是堆棧佈局總是-1說的呢?我想不完全綁定我想從一個按鈕,向下滾動菜單屏幕

<StackLayout 
      x:Name="ParentListViewStackLayout" 
      BackgroundColor="#242B3A" 
      Margin="0,0,0,0"> 
      <Image x:Name="imgLogo" Margin="0,60,0,15" 
         VerticalOptions="Center" 
         /> 
      <Image Source="{local:ImageResource BlankApp.Images.menu1.png} " 
        VerticalOptions="CenterAndExpand"> 
       <Image.GestureRecognizers> 
        <TapGestureRecognizer Tapped="btnMenuClick"/> 
       </Image.GestureRecognizers> 
      </Image> 
      <StackLayout 
       Spacing="0" 
       x:Name="ListViewStackLayout"> 
       <ListView x:Name="MenuListView" ItemsSource="{Binding 
MenuModals}" 
          SeparatorColor="{StaticResource ControlTextColor}" 
          ItemSelected="MenuListView_OnItemSelected"> 

        <ListView.ItemTemplate> 
         <DataTemplate> 
          <ViewCell > 
           <ViewCell.View> 
            <controls:CustomStackLayout> 
             <Label Text="{Binding MenuName}" FontSize="Medium" HorizontalOptions="Center" Style="{StaticResource LableStyle}" Margin="0,0,0,0"/> 
             <Label Text="{Binding MenuDescription}" FontSize="Micro" HorizontalOptions="Center" Style="{StaticResource LableStyle}" /> 
             <Label Text="" FontSize="Micro" HorizontalOptions="Center" Style="{StaticResource LableStyle}" HeightRequest="25" /> 
            </controls:CustomStackLayout> 
           </ViewCell.View> 
          </ViewCell> 
         </DataTemplate> 
        </ListView.ItemTemplate> 

       </ListView> 
      </StackLayout> 


     </StackLayout> 

代碼佈局Begind

public WashInternational() 
     { 
      InitializeComponent(); 
      this.BindingContextChanged += OnBindingContextChanged; 
MenuListView.BindingContextChanged += MenuListViewOnBindingContextChanged; 
     } 

private void OnBindingContextChanged(object sender, EventArgs eventArgs) 
     { 
      ShowMenue(false); 
     } 



     private void MenuListViewOnBindingContextChanged(object sender, EventArgs eventArgs) 
     { 
      ShowMenue(false); 
     } 

public void ShowMenue(bool isShow) 
     { 
      if (isShow == _isMenuShow) return; 
      var height = ListViewStackLayout.Height; 
      if (_menuHeight <= 0) 
      { 
       _menuHeight = height; 
      } 

      _isMenuShow = isShow; 
      if (isShow) 
      { 
       //MenuListView.TranslateTo(0, 0, 1000); 
       ParentListViewStackLayout.HeightRequest = ParentListViewStackLayout.Height + _menuHeight; 
       //ListViewStackLayout.ScaleTo(1, 500, Easing.Linear); 
      } 
      else 
      { 
       ParentListViewStackLayout.HeightRequest = ParentListViewStackLayout.Height - _menuHeight; 
       //MenuListView.TranslateTo(0,- 500, 1000); 
       //ListViewStackLayout.ScaleTo(0, 500, Easing.Linear); 
      } 


     } 

該代碼工作正常b UT斯達康我在初始狀態的問題,我無法啓動我的應用程序和menue被隱藏,因爲我不知道訪問我的棧佈局的高度正確的地方

回答

0

我沒有找到可以獲取的方法在開始的高度。我建議如果你dont't想要的應用程序開始你的菜單,你不應該設置的BindingContext開頭,但設置時要顯示的菜單,例如,一個按鈕單擊事件

private void Button_Clicked(object sender, EventArgs e) 
{ 
    List<Item> list = new List<Item>(); 
    list.Add(new Item { MenuName = "1", MenuDescription = "111" }); 
    list.Add(new Item { MenuName = "2", MenuDescription = "222" }); 
    list.Add(new Item { MenuName = "3", MenuDescription = "333" }); 
    BindingContext = new Model { List = list}; 
} 

所以listView會顯示出來,你可以很容易地獲得它包含stackLayout的高度。

+0

我試過這個解決方案,但仍堆棧佈局的高度-1 –

相關問題