【发布时间】:2018-05-24 19:33:33
【问题描述】:
我正在使用 xamarin.forms。有两个项目 Android 和 IOS。
我有一个包含以下代码的 ContentView 页面
<ContentView.Content>
<StackLayout x:Name="slMain" Padding="1" BackgroundColor="#7ABA45">
<StackLayout VerticalOptions="FillAndExpand" Padding="0,0,20,0" HeightRequest="50" HorizontalOptions="FillAndExpand">
<Label x:Name="lblTitle" VerticalOptions="CenterAndExpand" />
</StackLayout>
<StackLayout x:Name="sl" IsVisible="False" BackgroundColor="White">
</StackLayout>
</StackLayout>
</ContentView.Content>
// In Behind code(.cs file)
public ExpandCollapseStackLayout()
{
InitializeComponent();
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) =>
{
sl.IsVisible = !sl.IsVisible;
};
lblTitle.GestureRecognizers.Add(tapGestureRecognizer);
slMain.GestureRecognizers.Add(tapGestureRecognizer);
}
public string Title
{
get
{
return lblTitle.Text;
}
set
{
lblTitle.Text = value;
}
}
我想在设计时在 ContentPage 的内容视图的 StackLayout 中添加名为“sl”的控件。 我不想在运行时添加
请建议我如何在 Contentview stacklayout 中添加控件?
【问题讨论】:
-
您找到解决方案了吗?我也有同样的要求
标签: c# xamarin xamarin.ios xamarin.forms xamarin.android