gpt4 book ai didi

c# - 检测到布局循环。布局无法完成​​。检测到布局循环。布局无法完成

转载 作者:行者123 更新时间:2023-12-04 14:19:53 26 4
gpt4 key购买 nike

我知道有些问题的标题相同,但我找不到适合我的答案。

在 Xml 文件中得到了三重 ListBox ,它是由 3 个内部 Observable 集合构建的。(寄存器列表包含字段列表,字段列表包含 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 个寄存器时,我收到这条消息:

Layout cycle detected. Layout could not complete. Layout cycle detected. Layout could not complete.

不知道是什么意思。调试器也没有任何信息。

我几乎可以肯定它与 ScrollViewer 有关,因为当它被删除时,没有异常(exception)。但我需要这个 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;
}

}

Filling Registers 列表太复杂了,不能在这里添加,但为了简化:

    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;
}
}

最佳答案

我使用了 ListBox 内置的 ScrollViewer 而不是 ScrollViewer 布局,它似乎修复了这个错误。

<ListBox x:Name="RegistersListView" ItemsSource="{x:Bind registersList}" Grid.Row="1" 
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollMode="Enabled">

对于超过 50 个对象,性能仍然不佳,但这比异常要好。当使用 ListView 而不是 ListBox 时,性能更好,但不显示内置的 ScrollViewer。所以我不将此答案标记为可接受。

ListView 版本:

<ListView x:Name="RegistersListView" ItemsSource="{x:Bind registersList}" Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollMode="Enabled"

关于c# - 检测到布局循环。布局无法完成​​。检测到布局循环。布局无法完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56242888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com