C#

C# ,c#,wpf,loops,components,C#,Wpf,Loops,Components,但解决问题的方法是使用DataGrid/GridView。为什么要创建新组件。此外,您还可以使用listControl,并具有3个属性,您可以更改listboxNever-used listControl的模板。它能像我描述的那样使用吗?出于安全原因,我不会更多地使用DataGrid。如果其他一切都失败了,我会使用。你是在使用winform还是web app?那为什么不使用Grid呢。我的datagrid没有满足您的需求,这是一个设计问题。我将在一分钟内上传图像。但解决您问题的方法是使用Data

但解决问题的方法是使用DataGrid/GridView。为什么要创建新组件。此外,您还可以使用listControl,并具有3个属性,您可以更改listboxNever-used listControl的模板。它能像我描述的那样使用吗?出于安全原因,我不会更多地使用DataGrid。如果其他一切都失败了,我会使用。你是在使用winform还是web app?那为什么不使用Grid呢。我的datagrid没有满足您的需求,这是一个设计问题。我将在一分钟内上传图像。但解决您问题的方法是使用DataGrid/GridView。为什么要创建新组件。此外,您还可以使用listControl,并具有3个属性,您可以更改listboxNever-used listControl的模板。它能像我描述的那样使用吗?出于安全原因,我不会更多地使用DataGrid。如果其他一切都失败了,我会使用。你是在使用winform还是web app?那为什么不使用Grid呢。我的datagrid没有满足您的需求,这是一个设计问题。我马上上传图片。你也可以使用列表框。因为你只有一列。ListView用于不同的场景。您也可以使用ListBox。因为你只有一列。ListView用于不同的场景。
 public List<TOProduct> LoadRecords(int id)
    {
        List<TOProduct> i = new List<TOProduct>();

    try
        {


            string sql = "select * from tbl_records where user_id = " + id + " and product_status = true";

            con = ConnectionFactory.Connection();

            MySqlCommand cmd = new MySqlCommand(sql, con);

            con.Open();

            MySqlDataReader dtreader = cmd.ExecuteReader();


                while (dtreader.Read())//If there's any data.
                {
                    TOProduct x = new TOProduct();

                    x.Id = dtreader.GetInt16("product_id");
                    x.Link = dtreader.GetString("product_link");
                    x.Name = dtreader.GetString("product_name");
                    x.Type = dtreader.GetString("product_type");
                    x.Price = dtreader.GetDouble("product_price");
                    x.Store = dtreader.GetString("product_store");
                    x.BuyingDate = dtreader.GetDateTime("product_buyingDate").ToString("dd-MM-yyyy"); ;

                    i.Add(x);

                }

                con.Close();

            }
        }
        catch (MySqlException e)
        {
            throw new Exception(e.Message);
        }

        return i;
    }
    public object SearchButtonContent
    {
        get { return SearchButton.Content; }
        set { SearchButton.Content = value; }
    }

    public event RoutedEventHandler SearchButton_Clicked;

    public UserControl1()
    {
        InitializeComponent();
     SearchButton_Clicked += SearchButton_Click;
    }

    private void SearchButton_Click(object sender, RoutedEventArgs e)
    {
        if (SearchButton_Clicked != null)
        {
            SearchButton_Clicked(sender, e);
        }
    }
}  
  <Window x:Class="WpfTutorialSamples.ListView_control.ListViewItemTemplateSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ListViewItemTemplateSample" Height="150" Width="350">
<Grid>
            <ListView Margin="10" Name="lvProducts">
                    <ListView.ItemTemplate>
                            <DataTemplate>
                                    <WrapPanel>

                                            <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                                            <TextBlock Text=", " />

                                            <TextBlock Text="{Binding Price}" FontWeight="Bold" />
                                            <TextBlock Text=" (" />
                                            <TextBlock Text="{Binding Date}" TextDecorations="Underline" Foreground="Blue"  />
                                            <TextBlock Text=")" />
                                    </WrapPanel>
                            </DataTemplate>
                    </ListView.ItemTemplate>
            </ListView>
    </Grid>