C# 启用大文本时,堆栈布局不适合元素
我正试图使我的应用程序更兼容可访问性功能,当启用大文本时,我无法在水平方向的堆栈中容纳两个元素。你知道我该怎么解决这个问题吗C# 启用大文本时,堆栈布局不适合元素,c#,xaml,xamarin,xamarin.forms,xamarin.ios,C#,Xaml,Xamarin,Xamarin.forms,Xamarin.ios,我正试图使我的应用程序更兼容可访问性功能,当启用大文本时,我无法在水平方向的堆栈中容纳两个元素。你知道我该怎么解决这个问题吗 StackLayout horisontalContainer = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand,
StackLayout horisontalContainer = new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
List<string> dataList = this.registerCountries();
List<string> numberList = this.registerAreaCodes();
List<string> pickerData = new List<string>();
int i = 0;
foreach (var data in dataList)
{
pickerData.Add(data + " +" + numberList[i]);
i++;
}
countryCode = new Picker { Title = "Country code" };
countryCode.ItemsSource = pickerData;
countryCode.IsEnabled = true;
countryCode.SelectedIndex = 0;
countryCode.SelectedIndexChanged += (sender, args) =>
{
var tempValue = countryCode.Items[countryCode.SelectedIndex];
string[] words = tempValue.Split('+');
pickerSelection = words[words.Length-1];
};
phoneNbrEntry = new Entry
{
Placeholder = Localization.MobileNumber,
FontSize = 18,
BackgroundColor = Color.White.ToFormsColor(),
TextColor = Color.Black.ToFormsColor(),
Keyboard = Keyboard.Telephone,
};
图像:
堆栈布局将不适合其子元素的大小。在您的情况下,最好使用网格而不是堆栈布局,这样我们就可以将选择器和标签的宽度设置为相对值
Grid grid = new Grid
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
Padding = new Thickness(10,0),
RowDefinitions =
{
new RowDefinition { Height = new GridLength(60) },
},
ColumnDefinitions =
{
// the width of picker and label will fill half of the screen
new ColumnDefinition{Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition{Width = new GridLength(1, GridUnitType.Star) },
}
};
var countryCode = new Picker { Title = "Country code" };
//countryCode.ItemsSource = pickerData;
countryCode.IsEnabled = true;
countryCode.TitleColor = Color.Red;
countryCode.SelectedIndex = 0;
var phoneNbrEntry = new Entry
{
Placeholder = "11111111",
FontSize = 38,
BackgroundColor = Color.White,
TextColor = Color.Black,
Keyboard = Keyboard.Telephone,
};
grid.Children.Add(countryCode,0,0);
grid.Children.Add(phoneNbrEntry,1, 0);
Content = grid;
}
现在能用了吗?@LucasZhang MSFT是的。我希望得到一个堆栈解决方案,但我把它改成了网格
Grid grid = new Grid
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
Padding = new Thickness(10,0),
RowDefinitions =
{
new RowDefinition { Height = new GridLength(60) },
},
ColumnDefinitions =
{
// the width of picker and label will fill half of the screen
new ColumnDefinition{Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition{Width = new GridLength(1, GridUnitType.Star) },
}
};
var countryCode = new Picker { Title = "Country code" };
//countryCode.ItemsSource = pickerData;
countryCode.IsEnabled = true;
countryCode.TitleColor = Color.Red;
countryCode.SelectedIndex = 0;
var phoneNbrEntry = new Entry
{
Placeholder = "11111111",
FontSize = 38,
BackgroundColor = Color.White,
TextColor = Color.Black,
Keyboard = Keyboard.Telephone,
};
grid.Children.Add(countryCode,0,0);
grid.Children.Add(phoneNbrEntry,1, 0);
Content = grid;
}