C# 检测到布局周期。布局无法完成。检测到布局周期。布局无法完成
我知道有些问题的标题是相同的,但我找不到任何适合我的答案 获取Xml文件triple ListBox,它由3个内部可观察集合构建。 (包含包含int列表的字段列表的寄存器列表) Xaml:C# 检测到布局周期。布局无法完成。检测到布局周期。布局无法完成,c#,xaml,uwp,C#,Xaml,Uwp,我知道有些问题的标题是相同的,但我找不到任何适合我的答案 获取Xml文件triple ListBox,它由3个内部可观察集合构建。 (包含包含int列表的字段列表的寄存器列表) Xaml: <ScrollViewer HorizontalScrollBarVisibility="Auto"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <
<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个寄存器中时,我会得到以下信息:
检测到布局周期。布局无法完成。布局周期
检测。布局无法完成
不知道是怎么回事。调试器也没有任何信息
我几乎可以肯定它与ScrollViewer有关,因为当它被删除时,没有例外。但是我需要这个ScrollViewer,所以任何使用ScrollViewer的想法都是受欢迎的。
谢谢
编辑:
课程包括:
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;
}
}
公共类字段:INotifyPropertyChanged
{
公共字符串名称;
公共整数偏移;
公共整数长度;
公共字符串描述;
私有UInt64_值;
私有ObservableCollection位列表=新ObservableCollection();
公共可观测收集比特列表
{
得到
{
返回新的ObservableCollection(位列表);
}
设置
{
//待办事项
}
}
公共事件属性更改事件处理程序属性更改;
公共void OnPropertyChanged(字符串propertyName)
{
PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(propertyName));
}
公共字段(字符串_名称)
{
名称=_名称;
}
重写公共字符串ToString()
{
返回名称;
}
公共无效值(UInt64值)
{
_价值=价值;
#pragma警告禁用CS4014
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,()=>
{
for(int i=0;i>1;
}
OnPropertyChanged(“BitsList”);
});
#pragma警告恢复CS4014
}
}
公共班级登记册
{
公共字符串名称;
公共UInt64——死亡价值;
公共UInt64值;
公共整数偏移;
公共整数指数;
公共字符串描述;
公共整数寄存器的大小;
公共ObservableCollection reg_字段=新ObservableCollection();
公共寄存器(字符串_名称)
{
名称=_名称;
}
}
填写登记表太复杂,无法在此添加,但为了简化:
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;
}
}
public observetecollection registerList=new observetecollection();
私有void InnerDataCreator()
{
实例=新实例();
registerList=instances.PopulateRegistersData();
}
公共可观测集合人口统计数据()
{
const int REG_AMOUNT=100;
const int REG_SIZE=32;
ObservableCollection寄存器=新的ObservableCollection();
对于(int regIndex=0;regIndex<ListBox x:Name="RegistersListView" ItemsSource="{x:Bind registersList}" Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollMode="Enabled">
<ListView x:Name="RegistersListView" ItemsSource="{x:Bind registersList}" Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollMode="Enabled"