簡體   English   中英

它是 Xamarin StackLayout children.Add, Clear function 中的錯誤嗎?

[英]Is it a bug in Xamarin StackLayout children.Add, Clear function?

靜態創建按鈕時,清除和添加stacklayout沒有問題。 但是,在動態創建按鈕並清除並添加時,會出現問題。

動態創建時我需要單獨做些什么嗎? 我是否也必須在代碼中創建布局本身?

我不明白。 這就像一個錯誤。

<ContentView x:Name="xMainContentsView" Grid.Row="1" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

            <ScrollView Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                <StackLayout x:Name="xView" Margin="35,80,35,80" Spacing="25" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                    <Button Text="g02" Clicked="Button_Clicked"></Button>                   
                </StackLayout>
            </ScrollView>
            
            <!--<StackLayout x:Name="xPageView"  Orientation="Horizontal" HorizontalOptions="FillAndExpand">
            </StackLayout>-->
</ContentView>


private void Button_Clicked(object sender, EventArgs e)
        {
            xView.Children.Clear();
            xView.Children.Add(new Spectrum(this));
        }




private void InitializeCompView()
        {
              
            foreach (MainViewMeasureType contents in Enum.GetValues(typeof(MainViewMeasureType)))
            {
                CtrlButton button = new CtrlButton
                {
                    WidthRequest = 180,
                    HeightRequest = 180,
                    Text = contents.ToString(),
                    ClassId = contents.ToString(),
                };
                button.Pressed += BtnMainContentClick;

                xView.Children.Add(button);
            } 
        }
        



private void BtnMainContentClick(object sender, EventArgs e)
        {
            xView.Children.Clear();
            xView.Children.Add(new Spectrum(this));
        }

我創建了一個示例來測試 StackLayout children.Add, Clear function 並遇到了同樣的問題。

此外,異常消息提到了 FasterRender,然后我在 mainactivity 中禁用了它。 但是同樣的異常來了,所以我改變了button.Pressed += BtnMainContentClick; button.Clicked += BtnMainContentClick; . 它運作良好。

因此,您也可以嘗試此操作並將其作為錯誤報告給 github 上的 xamarin。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM