2012-10-09 70 views
-4
IEnumerable<string> peopleWithInvalidAge = 
        (from age in User 
        where age < 0 
        select name).Distinct(); 

MessageBox.show("The people who have invalid age are {0}" , string.Join(", ", peopleWithInvalidAge)) 

这将显示字符串输出。但我想要的是,输出应以表格形式显示。在调用MessageBox.show时使用名称和年龄。在C中包含表的消息框#

如果我们能消息盒子里面彰显随后也将是巨大的

请帮助。

+1

七票反对,而不是一个评论,以帮助海报知道为什么。 SO应该比这更好。 –

+0

@JohnArlen模糊的多部分问题,3回答,没有回应OP – Paparazzi

回答

1

这是用于WPF的

格式化可以使用Window。
您可以通过ctor中的IEnumerable。
Window.ShowDialog是模态的。

Window.ShowDialog Method

Window1 win = new Window1(new List<string> { "john", "susan" }); 
win.ShowDialog(); 

public Window1(IEnumerable<string> names) 
{ 
    Names = names; 
    InitializeComponent(); 
} 
public IEnumerable<string> Names { get; private set; } 

<Window x:Class="ListViewUpdate.Window1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     DataContext="{Binding RelativeSource={RelativeSource self}}" 
     Title="Window1" Height="300" Width="300"> 
<Grid> 
    <ListView ItemsSource="{Binding Path=Names}" /> 
</Grid> 
</Window> 

主持人有三个部分质疑。
模态,传递数据和格式。
另一个答案不解决模态或将数据传递给窗口。
我在创建传递和格式化示例时发布了消息。

+0

对不起,延迟回复。在一些讨论中,我发现我们无法将此功能扩展到自定义消息框。但从你的解释我试着你的方法,它运作良好。谢谢 – StackOverflowVeryHelpful

1

在WPF中,你必须创建窗口

的XAML

<my:Datagrid x:Name="test" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" CanUserAddRows="True" ItemsSource="{Binding}" AutoGenerateColumns="False"> 
    <my.DataGrid.Columns> 
     <my:DataGridTextColumn Header="Your Collection" Binding="{Binding}"/> 
    </my.DataGrid.Columns> 
</my:Datagrid> 

代码隐藏

public Window() 
{ 
    InitializeComponent(); 

    test.DataContext = peopleWithInvalidAge ; 
} 
1

像你想你可以使用一个窗口,与showdialg,使用按钮和数据网格(使它就像一个MessageBox),并与Dialog结果一起工作,

只是一个想法做到这一点

+0

我发现没有直接的方式让WPF中的自定义消息拥有上面提到的所有这些功能。这将需要创建一个类似于消息框的xaml。 – StackOverflowVeryHelpful