2016-03-30 42 views
0

我有這樣的代碼:Xamarin.forms如何改變視圖屬性在運行時

StackLayout stackLayout = new StackLayout { 

    Spacing = 0, 
    Children = 
    { 
     new Label 
     { 
      Text = "StackLayout", 
      HorizontalOptions = LayoutOptions.Start, 
      FontSize = 20 
     } 
    } 

} 

請告訴我改變空間的性質和字號在運行時的最佳方式?

+0

你有sizeChanged事件可用與任何VisualElement, 在那裏你可以獲得佈局訪問權限,所有的孩子都可以在運行時修改 –

回答

0

你有你的StackLayout一個參考,所以要改變它的屬性,你只想做:

stackLayout.Spacing = 10; 

要改變你的標籤,你需要一個參考保持它:

Label label = new Label 
     { 
      Text = "StackLayout", 
      HorizontalOptions = LayoutOptions.Start, 
      FontSize = 20 
     }; 

StackLayout stackLayout = new StackLayout { 

    Spacing = 0, 
    Children = 
    { 
     label 
    } 
} 

然後你可以在運行時修改它

label.FontSize = 30;