• [No0000F0]DataGrid一行Row添加ToolTip,wpf


    1.

    <Window x:Class="WpfApp7.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp7"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525" >
    
        <Grid>
            <DataGrid Name="dataGrid" AutoGenerateColumns="False" CanUserAddRows="False">
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="First Name">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding FirstName}">
                                    <TextBlock.ToolTip>
                                        <StackPanel>
                                            <TextBlock Text="{Binding FirstName}"></TextBlock>
                                            <TextBlock Text="{Binding LastName}"></TextBlock>
                                            <TextBlock Text="{Binding EmailId}"></TextBlock>
                                            <TextBlock Text="{Binding Contact}"></TextBlock>
                                        </StackPanel>
                                    </TextBlock.ToolTip>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Email Id" Binding="{Binding EmailId}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Contact" Binding="{Binding Contact}"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Window>
    namespace WpfApp7
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                ObservableCollection<Employee> empList =
                    new ObservableCollection<Employee>();
                for (int i = 0; i < 20; i++)
                {
                    Employee emp = new Employee
                    {
                        FirstName = "FirstName" + i,
                        LastName = "LastName" + i,
                        EmailId = "EmailId" + i,
                        Contact = "Contact" + i,
                    };
                    empList.Add(emp);
                }
                dataGrid.ItemsSource = empList;
            }
        }
        public class Employee
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string EmailId { get; set; }
            public string Contact { get; set; }
        }
    }

     2.

    <Window x:Class="WpfApp7.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp7"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525" >
    
        <Grid>
            <DataGrid Name="grid" AutoGenerateColumns="False">
                <DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <TextBlock Background="Orange" Text="{Binding Contact}" TextWrapping="Wrap"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    </DataTemplate>
                </DataGrid.RowDetailsTemplate>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="FirstName" Binding="{Binding FirstName}" />
                    <DataGridTextColumn Header="LastName" Binding="{Binding LastName}" />
                    <DataGridTextColumn Header="EmailId" Binding="{Binding EmailId}" />
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Window>
    namespace WpfApp7
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                ObservableCollection<Employee> empList =
                    new ObservableCollection<Employee>();
                for (int i = 0; i < 20; i++)
                {
                    Employee emp = new Employee
                    {
                        FirstName = "FirstName" + i,
                        LastName = "LastName" + i,
                        EmailId = "EmailId" + i,
                        Contact = "Contact" + i,
                    };
                    empList.Add(emp);
                }
                grid.ItemsSource = empList;
            }
        }
        public class Employee
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string EmailId { get; set; }
            public string Contact { get; set; }
        }
    }
  • 相关阅读:
    谷歌控制台的使用
    等比例居中
    display:block、inline、inline-block的区别及应用案例
    省市县三级联动逻辑
    页面滑动至某处,固定导航。
    类加载器在Tomcat中的应用
    MySQL中一些关于索引的知识点
    Spring中AOP相关源码解析
    Spring中Bean的实例化与DI的过程
    我该如何学习spring源码以及解析bean定义的注册
  • 原文地址:https://www.cnblogs.com/Chary/p/6991654.html
Copyright © 2020-2023  润新知