1 回答
TA贡献1810条经验 获得超4个赞
我找到了解决这个问题的方法。我从 更改为 以下内容:StackLayoutGrid
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ctrl:CameraView Grid.Row="0" />
<ctrl:SpottedView Grid.Row="1" RowHeight="40" />
</Grid>
</ContentPage.Content>
然后我添加了一个 自定义 ,如下所示:ListViewSpottedView
namespace Foo.Controls
{
public class SpottedView : ListView
{
ObservableCollection<string> items;
public SpottedView() : base()
{
items = new ObservableCollection<string>();
ItemsSource = items;
items.CollectionChanged += onItemsChanged;
// TODO: test purposes, remove later
var autoEvent = new AutoResetEvent(false);
var stateTimer = new Timer(onTimer, autoEvent, 1000, 2000);
}
void onItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
MainThread.BeginInvokeOnMainThread(() =>
{
HeightRequest = RowHeight * items.Count;
InvalidateMeasure();
});
}
// TODO test purposes, remove later.
void onTimer(object state)
{
MainThread.BeginInvokeOnMainThread(() =>
{
if (items.Count < 2)
{
items.Add("Blah");
}
else
{
items.Clear();
}
});
}
}
}
像吊饰一样工作。
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
