【问题标题】:Message Box to contain Table in C#在 C# 中包含表格的消息框
【发布时间】:2012-10-09 17:20:46
【问题描述】:
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) )

这会将输出显示为 string 。但我想要的是输出应该以表格形式显示。调用 MessageBox.show 时带有名称和年龄。

如果我们可以在消息框内突出显示,那也很棒

请帮忙。

【问题讨论】:

  • 七票反对,没有一条评论可以帮助发帖者知道原因。 SO应该比那更好。
  • @JohnArlen Vague 多部分问题有 3 个答案,OP 没有回应

标签: c# .net wpf winforms


【解决方案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>

版主有三个部分要提问。
模态、传递数据和格式化。
另一个答案不涉及模态或将数据传递到窗口。
我在创建传递和格式化示例时发布。

【讨论】:

  • 抱歉回复晚了。在一些讨论中,我发现我们无法将此功能扩展到自定义消息框。但是根据您的解释,我尝试了您的方法,效果很好。谢谢
【解决方案2】:

在 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 ;  
}

【讨论】:

    【解决方案3】:

    您可以为此使用窗口,通过 showdialg,使用您想要的按钮和数据网格(使其像 MessageBox)并使用 Dialog 结果,

    只是一个想法

    【讨论】:

    • 我发现没有直接的方法可以让 WPF 中的自定义消息拥有我上面提到的所有这些功能。它需要创建一个类似于消息框的 xaml。
    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 2020-12-03
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 2013-09-29
    相关资源
    最近更新 更多