Xamarin ยังไงจะลบการรายการในแบบเจาะจงแถวอยู่ในแนวตาราง

0

คำถาม

ฉันต้องตารางที่ผมกำลังพยายามเอาเป็นรายการอยู่เฉพาะบนเส้น. มันเป็นไปเรื่อยๆแล้วตอนที่มันจะไปที่ที่สองเส้นมันเอารายการในสองสายและยังอยู่ในเส้นแรกของกรอบ. ยังไงฉันสามารถปรับจะลบเพียงบรรทัดที่ฉันต้องการ?

โปรดจำไว้ว่าอะไรที่ฉันกำลังพยายามทำคือคัดลอกเส้นแรกของกรอบที่สองเดียวที่แก้ไขที่ pow(b2)และในที่สามที่ฉันจะคัดลอกที่สองเส้นหรอกนะแต่แก้ -4*5(-4*น).

นี่เป็นพื้นที่แสดงภาพตัวอย่างสิ่งที่กำลังเกิดขึ้น

นี่ คือรหัสที่จะเล่พวกนี้บรรทัดที่เข้าใจ: มันเข้าก่อนใน if(fields == null) เพราะเป็นนิดหลังจากนั้นไป else:

for (int i = 0; i < qntLines; i++)
{
   string field = lines[i].Substring(0, lines[i].IndexOf('#'));
   string operation = lines[i].Substring(lines[i].IndexOf('#') + "#".Length);

   CreateResultLine(field, operation, i, listTexts);
}

private void CreateResultLine(string field, string operation, int i, List<string> listTexts)
{
            string[] fields = null;
            List<string> texts = new List<string>();
            string text = string.Empty;
            dynamic textResult;
            int count = new int();

            if (field.Contains(','))
                fields = field.Split(',', (char)StringSplitOptions.RemoveEmptyEntries);
            
            if (fields == null)
            {
                text = listTexts[int.Parse(field)];
                text = RemovePow(text);
                texts.Add(text);
                textResult = ExecuteOperation(texts, operation);
                
                gridFrame.Children.RemoveAt(int.Parse(field) + 1);
                gridFrame.Children.Add(new Label() { Text = textResult.ToString(), HorizontalTextAlignment = TextAlignment.Center, 
                    TextColor = Color.Blue, HorizontalOptions = LayoutOptions.Center }, int.Parse(field) + 1, i);
            }
            else
            {
                foreach (var item in fields)
                {
                    string noPow = string.Empty;
                    noPow = RemovePow(listTexts[int.Parse(item)]);
                    texts.Add(noPow);
                    ++count;
                }
                textResult = ExecuteOperation(texts, operation);

                for (int i2 = int.Parse(fields[0]); i2 <= int.Parse(fields[1]);)
                {
                    gridFrame.Children.RemoveAt(int.Parse(fields[0]));
                    
                    ++i2;
                }

                gridFrame.Children.Add(new Label() { Text = textResult.ToString(), HorizontalTextAlignment = TextAlignment.Center, 
                    TextColor = Color.Blue, HorizontalOptions = LayoutOptions.Center }, int.Parse(fields[0]) + 1, i);
            }
        }
c# dynamic grid xamarin
2021-11-23 23:29:00
2

คำตอบที่ดีที่สุด

1

ที่นี่คือสมบูรณ์ตัวอย่างของทำงานกับเซลล์ของตาราง

ในสงครามแย่งชิงยุทธศาสนั่นคุณก่อสร้างทั้งหมดห้องขังของตัวเอง ที่ฉันใช้ Label ในแต่ละเส้นกริดมือถือ เพื่อทำให้มันง่ายกว่าที่จะเข้าใจฉันจัดเตรียมกันและมือถือเป็นข้อความที่"CellNumber"นั่นฉันกำหนดมัน ครั้งหนึ่งคุณเข้าใจว่าเกิดอะไรขึ้นวางเป็นข้อความว่างเปล่า "" เป็นที่เริ่มการมูลค่าอยู่

เพื่อทำให้มันง่ายที่จะหาห้องขังนั้นเป็น Dictionary บรรจุพวกเขา CellNumber(row, column) ให้ปืน key เพื่อที่พจนานุกรมหาคนที่สัมพันธ์กันนะ

Calculate ปุ่มนี้จะทำให้มีการเปลี่ยนแปลงนิดหน่อต้องเซลล์ดังนั้นคุณสามารถเห็นได้ว่าจะทำอย่างนั้น

ผมแนะนำว่าให้เป็นเรื่องไม่ได้ทำการเพิ่มหรือลบเซลล์(เด็กของแนวตาราง)กครั้งนี่เป็นสามารถใช้ถอ. แทนที่จะแสดงหรือซ่อนมือถือหรอก เอานี่นายจัดการเรื่องนี้โดยการเปลี่ยน Text ของ Label. สำหรับอีกประเภท Views คุณอาจจะเปลี่ยน View.IsVisible ที่จริงหรือไม่จริง.

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ManipulateGridChildren.MainPage">

    <Grid x:Name="Formulas" BackgroundColor="#A0A0A0"
          RowSpacing="2" ColumnSpacing="2" Padding="2"
          ColumnDefinitions="*,*,*,*,*,*,*,*"
          RowDefinitions="40,40,40,Auto">
        <Button Grid.Row="3" Text="Calc" Command="{Binding CalcCommand}" />
    </Grid>

</ContentPage>

MainPage.xaml.à™àà§à•à£àà™:

using System.Collections.Generic;
using Xamarin.Forms;

namespace ManipulateGridChildren
{
    public partial class MainPage : ContentPage
    {
        const int NRows = 3;
        static int NColumns = 8;
        const int MaxColumns = 100;

        private Dictionary<int, Label> cells = new Dictionary<int, Label>();

        public MainPage()
        {
            InitializeComponent();
            AddCells();
            CalcCommand = new Command(Calculate);
            BindingContext = this;
        }

        public Command CalcCommand { get; set; }

        private void Calculate()
        {
            SetCellText(0, 0, "A");
            SetCellText(0, 2, "B");
            SetCellText(1, 0, "C");
            SetCellText(2, 3, "D");
            SetCellBackground(2, 3, Color.Pink)
        }

        private void SetCellText(int row, int column, string text)
        {
            cells[CellNumber(row, column)].Text = text;
        }

        private void SetCellBackground(int row, int column, Color color)
        {
            cells[CellNumber(row, column)].BackgroundColor = color;
        }

        private void AddCells()
        {
            // Grid rows and columns are numbered from "0".
            for (int row = 0; row < NRows; row++) {
                for (int column = 0; column < NColumns; column++) {
                    var cell = AddCell(row, column);
                    cells[CellNumber(row, column)] = cell;
                }
            }

            // Add "frames" around some rows.
            // AFTER adding the cells, so drawn on top.
            AddFrame(0, 1, 0, NColumns);
            AddFrame(1, 2, 0, NColumns);
        }

        private Label AddCell(int row, int column)
        {
            var cell = new Label();
            // For debugging - show where each cell is.
            // Once you understand, change this to an empty string.
            cell.Text = $"{CellNumber(row, column)}";
            cell.BackgroundColor = Color.White;
            cell.HorizontalTextAlignment = TextAlignment.Center;
            cell.VerticalTextAlignment = TextAlignment.Center;
            Formulas.Children.Add(cell, column, row);
            return cell;
        }

        // Assign unique number to each cell.
        private int CellNumber(int row, int column)
        {
            return row * MaxColumns + column;
        }

        private void AddFrame(int row, int rowSpan, int column, int columnSpan)
        {
            var rect = new Xamarin.Forms.Shapes.Rectangle {
                Stroke = new SolidColorBrush(Color.Black),
                StrokeThickness = 2
            };

            Formulas.Children.Add(rect, column, column + columnSpan, row, row + rowSpan);
        }
    }
}
2021-11-24 19:14:51

ขอบคุณฉันตามความคิดสร้างรายการของแนวตารางแล้วก็แสดงว่ามันเห็นได้หรือไม่
Que44
0

นิดหน่อสับสนของสิ่งที่คุณกำลังพยายามที่จะประสบความสำเร็จในส่วแต่นี่คือ sugestion.

ฉันขอแนะนำจะออกไป MVVM รูปแบบ. กำลังหลอกส่วนติดต่อผู้เข้ารหัสไม่ใช่ความคิดที่เจ๋งหรอกนะ

<ContentPage.BindingContext>
   <local: MainViewModel />
</ContentPage.BindingContext>

<ContentPage.Content>

  <ListView ItemSource={Binding ListOfItems}>
     <ListView.ItemTemplate>
       <DataTemplate>
          <ViewCell>
             <Label Text={Binding .}/>
          <ViewCell>
       </DataTemplate>
     </ListView.ItemTemplate>
  </ListView>
</ContentPage.Content>

MainViewModel.à™àà§à•à£àà™

public class MainViewModel : INotifyPropertyChanged
{

public ObservableCollection<string> ListOfItems {get;set;} = new ObservableCollection<string>();

public void DeleteAnItem(string s)
{
  ListOfItems.Remove(s);
}

public void AddItem(string s)
{
 ListOfItems.Add(s);
}

public void RemoveAtIndex(int i)
{
  ListOfItems.RemoveAt(i);
}

#region TheRestOfPropertyChanged
...
#endregion
}

ทุกเปลี่ยนคุณทำรายการจะ visibile ในส่วนติดต่อผู้ใช้ของคุณ.

2021-11-24 19:06:24

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่