【发布时间】:2019-09-16 15:28:00
【问题描述】:
出于某些需要,我必须在我的内容页面中添加一个网格。我试过这个:
public HomePage()
{
Grid = new Grid
{
RowDefinitions = new RowDefinitionCollection() { new RowDefinition() { Height = GridLength.Star } },
ColumnDefinitions = new ColumnDefinitionCollection() { new ColumnDefinition() { Width = GridLength.Star } },
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
ColumnSpacing = 0,
RowSpacing = 0,
};
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == ContentProperty.PropertyName)
{
if (!IsGridSet)
{
Grid.Children.Add(Content);
IsGridSet = true;
Content = Grid;
}
}
}
它似乎可以正常工作,因为页面显示正确,但没有任何控件起作用,按钮,条目一切似乎都已停用或无法访问,就像将另一个透明组件放置在前台一样。
【问题讨论】:
-
我发现了更多。如果我在页面加载按钮操作时这样做,它就可以工作......所以我不明白为什么它以前不工作。
-
当您将内容放入 Grid 时,它究竟包含什么?
-
@FreakyAli 它包含另一个网格。
-
为什么要在 ViewModel 中添加 UI 元素?
-
它不在 ViewModel ....
标签: xamarin xamarin.forms