【发布时间】:2018-12-06 14:32:44
【问题描述】:
我必须在段控制中实现内容视图。这是我必须实现的 UI
如您所见,有两个内容视图,即供应商名称和产品/服务。我关注 this example 并在 iOS 中实现了它,但在 android 中,它只是一个空白应用程序。这是我的 XAML 代码。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:SegmentedApp" x:Class="SegmentedApp.SegmentedAppPage" >
</ContentPage>
This is the code behind
public partial class SegmentedAppPage : ContentPage
{
SegmentedControl segControl;
SegmentedControlOption scOptionOne;
SegmentedControlOption scOptionTwo;
Grid grid;
View1 view1 = new View1();
View2 view2 = new View2();
public SegmentedAppPage()
{
InitializeComponent();
segControl = new SegmentedControl();
segControl.SelectedValue = "One";
scOptionOne = new SegmentedControlOption();
scOptionTwo = new SegmentedControlOption();
scOptionOne.Text = "One";
scOptionTwo.Text = "Two";
segControl.Children.Add(scOptionOne);
segControl.Children.Add(scOptionTwo);
grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.Children.Add(segControl, 0, 0);
grid.Children.Add(view1, 0, 1);
this.Content = grid;
segControl.ValueChanged += SegControl_ValueChanged;
}
private void SegControl_ValueChanged(object sender, EventArgs e)
{
SegmentedControl control = sender as SegmentedControl;
if (control.SelectedValue is "One")
{
grid.Children.Remove(view2);
grid.Children.Add(view1, 0, 1); //This line
}
else if (control.SelectedValue is "Two")
{
grid.Children.Remove(view1);
grid.Children.Add(view2, 0, 1); //This line
}
this.Content = grid;
}
}
这是我的观点1
public View1()
{
Content = new StackLayout
{
BackgroundColor = Color.Green,
Children = {
new Label { Text = "View1" }
}
};
}
我没有为此找到自定义渲染器。我不知道我应该如何为这个段控件实现自定义渲染器。这是我项目的link。
【问题讨论】:
-
如果可能,请提供您的项目链接。
-
是的,我在最后提到了项目链接。
-
但这并没有打开。删除 bin 和 obj 文件夹后提供以减小大小。
-
@CGPA6.4 我已经放了最新的链接。我从 bin 和 obj 文件夹中删除了该文件。
标签: xamarin xamarin.forms uisegmentedcontrol