检测到布局周期.布局无法完成.检测到布局周期.布局无法完成 [英] Layout cycle detected. Layout could not complete. Layout cycle detected. Layout could not complete
问题描述
我知道有些问题的标题相同,但是找不到适合我的答案.
I know there are some questions with same head line, but I couldn't find any answer that worked for me.
获得Xml文件Triple ListBox,它是由3个内部Observable集合构建的.(包含有包含int列表的字段列表的寄存器列表).
Got in Xml file triple ListBox , which was built from 3 inner Observable collection. (List of Registers which contains list of Fields which contains list of int).
Xaml:
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
<RowDefinition MaxHeight="50"/>
</Grid.RowDefinitions>
<ListBox x:Name="RegistersListView" ItemsSource="{x:Bind registersList}" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="structures:Register">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Bind name}" Grid.Row="0" />
<ListBox x:Name="FieldsListView" ItemsSource="{x:Bind reg_fields}" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="structures:Field">
<StackPanel>
<TextBlock Text="{x:Bind name}"/>
<ListBox x:Name="BitsListView" ItemsSource="{x:Bind bitsList}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</ScrollViewer>
但是当我的数据存储在约60个以上的寄存器中时,我会收到此消息:
but when my data is in more than ~60 registers I get this message:
检测到布局周期.布局无法完成.布局周期检测到.布局无法完成.
Layout cycle detected. Layout could not complete. Layout cycle detected. Layout could not complete.
不知道是关于什么的.调试器也没有信息.
Don't know what is it about. The debugger has no information either.
我几乎可以确定它与ScrollViewer有关,因为将其删除时也不例外.但是我需要这个ScrollViewer,因此也欢迎任何使用ScrollViewer进行操作的想法.谢谢.
I'm almost sure it has to do with the ScrollViewer because when it is removed, there is no exception. but I need this ScrollViewer, so any ideas to do something with ScrollViewer are welcome too. Thanks.
这些类是:
public class Field : INotifyPropertyChanged
{
public string name;
public int offset;
public int length;
public string description;
private UInt64 _value;
private ObservableCollection<int> bitsList = new ObservableCollection<int>();
public ObservableCollection<int> BitsList
{
get
{
return new ObservableCollection<int>(bitsList);
}
set
{
//todo
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public Field(string _name)
{
name = _name;
}
override public string ToString()
{
return name;
}
public void Value(UInt64 value)
{
_value = value;
#pragma warning disable CS4014
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
for (int i = 0; i < length; i++)
{
bitsList.Add(Convert.ToInt32(value & 1));
value = value >> 1;
}
OnPropertyChanged("BitsList");
});
#pragma warning restore CS4014
}
}
public class Register
{
public string name;
public UInt64 _deafult_value;
public UInt64 value;
public int offset;
public int index;
public string description;
public int register_size;
public ObservableCollection<Field> reg_fields = new ObservableCollection<Field>();
public Register(string _name)
{
name = _name;
}
}
填充寄存器列表太复杂了,无法在此处添加,只是为了简化:
Filling Registers list is too complicated to add here but for simplification:
public ObservableCollection<Register> registersList = new ObservableCollection<Register>();
private void InnerDataCreator()
{
Instances instances = new Instances();
registersList = instances.PopulateRegistersData();
}
public ObservableCollection<Register> PopulateRegistersData()
{
const int REG_AMOUNT = 100;
const int REG_SIZE = 32;
ObservableCollection<Register> registers = new ObservableCollection<Register>();
for (int regIndex = 0; regIndex < REG_AMOUNT; regIndex++)
{
Register register = new Register("reg_" + regIndex.ToString());
register.description = "register description _***_ " + regIndex.ToString();
register.register_size = REG_SIZE;
ObservableCollection<Field> fields = new ObservableCollection<Field>();
int offset = 0;
/* 4 fields in each register */
for (int fieldNum = 0; fieldNum < 4; fieldNum++)
{
string fieldName;
if(regIndex < REG_AMOUNT / 2)
{
fieldName = "reg_" + regIndex.ToString() + " Field_" + fieldNum.ToString();
}
else
{
fieldName = "################ reg_" + regIndex.ToString() + " Field_" + fieldNum.ToString() + "###################";
}
Field field = new Field(fieldName);
field.description = "field description. reg: " + regIndex.ToString() + ". field: " + fieldNum.ToString();
field.length = 8;
field.offset = offset;
field.Value(BitConverter.GetBytes(170)[0]); /* 10101010 */
register.reg_fields.Add(field);
offset += field.length;
}
registers.Add(register);
}
return registers;
}
}
推荐答案
我通过 foreach
循环填充了一些 StackLayout
.它们每个都包含在固定高度的 ScrollViewer
中.
I had a few StackLayout
s populated via foreach
loops. They were each contained within a ScrollViewer
of fixed height.
当内容太大时,它开始崩溃,并出现模糊的检测到布局循环"错误.
When the content was too great, it started to crash with the obscure 'layout cycle detected' error..
我将 StackLayout
s更改为 Grid
s,最后解决了这个非常烦人的问题.
I changed the StackLayout
s to Grid
s, and finally this extremely annoying problem was solved.
更新:一年后,我的应用又遇到了问题.我通过在有问题的网格"视图中添加 VerticalAlignment
属性来对其进行修复...
Update: 1 year later my application suffered from the problem again. I fixed it by adding a VerticalAlignment
property to the offending Grid view...
这篇关于检测到布局周期.布局无法完成.检测到布局周期.布局无法完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!