【问题标题】:create popup using silverlight and add a data grid to the popup使用 silverlight 创建弹出窗口并向弹出窗口添加数据网格
【发布时间】:2014-08-21 15:25:09
【问题描述】:

我需要在 Silverlight 项目的弹出窗口中添加一个网格。我已在 mainpage.xaml.cs 文件中添加了此代码,并创建了一个弹出窗口。 但我需要添加一个网格来显示数据库中的表格。

    private void Button_Click_1(object sender, RoutedEventArgs e)

    {

        popup p = new Popup();Border border = new Border();
        border.BorderBrush = new SolidColorBrush(Colors.Black);
        border.BorderThickness = new Thickness(5.0);

        StackPanel panel1 = new StackPanel();
        panel1.Background = new SolidColorBrush(Colors.LightGray);

        Button button1 = new Button();
        button1.Content = "Close";
        button1.Margin = new Thickness(2.0);
        button1.Click += new RoutedEventHandler(button1_Click);
        TextBlock textblock1 = new TextBlock();
        textblock1.Text = "The popup control";
        textblock1.Margin = new Thickness(5.0);
        panel1.Children.Add(textblock1);
        panel1.Children.Add(button1);
        border.Child = panel1;

        Grid grid1 = new Grid();
        // i need to bind this grid to data from the sql database and attach this grid to the  popup     


        // Set the Child property of Popup to the border 
        // which contains a stackpanel, textblock and button.
        p.Child = border;
        p.DataContext = 
        // Set where the popup will show up on the screen.
        p.VerticalOffset = 200;
        p.HorizontalOffset = 300;

        // Open the popup.
        p.IsOpen = true;


    }

【问题讨论】:

  • 有什么问题?您在寻找如何bind to DataGrid 吗?还是 Popup 不支持 DataGrids 作为子元素?你能澄清一下吗?
  • 其实我是 Silverlight 的初学者。如果我能做到这两点就太好了。即绑定到数据网格并将该数据网格添加到弹出窗口。
  • 当我点击一个按钮时,应该会出现一个弹出窗口,显示一个包含数据库数据的表格..
  • 您是否尝试过搜索:如何绑定到DataGrid?以及如何以编程方式将 DataGrid 添加为子元素?我确信有很多关于这些问题的信息。
  • 是的。我已经完成了数据网格的绑定部分。在 WPF 应用程序中。但我需要一个 Silverlight 应用程序,我可以在其中将此数据网格添加为弹出窗口的子窗口。我搜索了很多。但找不到正确的结果。你能推荐一些有用的链接吗?

标签: c# wpf silverlight popup


【解决方案1】:

Grid 是一个布局控件,不用于显示表格。对于表格数据,您需要一个 DataGrid 控件。

List<Customer> customerList = new List<Customer>();

var dataGrid = new DataGrid();
dataGrid.ItemsSource = customerList;

Popup popup = new Popup();
popup.Child = dataGrid;
popup.IsOpen = true;

【讨论】:

    猜你喜欢
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    相关资源
    最近更新 更多