首页 > 其他分享 >Wpf Combobox display multiple fields columns properties

Wpf Combobox display multiple fields columns properties

时间:2024-04-03 14:46:39浏览次数:26  
标签:multiple Windows Combobox System MainWindow Loaded using properties

 <ComboBox Grid.Row="0" x:Name="cbx" VirtualizingPanel.VirtualizationMode="Recycling"
           HorizontalAlignment="Stretch" VerticalContentAlignment="Center" 
           FontSize="30" SelectedIndex="0" >
     <ComboBox.ItemTemplate>
         <DataTemplate>
             <TextBlock Style="{StaticResource tbStyle}">
                 <TextBlock.Text>
                     <MultiBinding StringFormat="{}{0}_____{1}_____{2}">
                         <Binding Path="Id"/>
                         <Binding Path="Name"/>
                         <Binding Path="ReleaseDate"/>
                     </MultiBinding>
                 </TextBlock.Text>
             </TextBlock>
         </DataTemplate>
     </ComboBox.ItemTemplate>
 </ComboBox>

 

 

 

The whole code 

//xaml
<Window x:Class="WpfApp35.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:WpfApp35" WindowState="Maximized"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}" x:Key="tbStyle">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="Red"/>
                    <Setter Property="FontSize" Value="50"/>
                    <Setter Property="FontWeight" Value="ExtraBold"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ComboBox Grid.Row="0" x:Name="cbx" VirtualizingPanel.VirtualizationMode="Recycling"
                  HorizontalAlignment="Stretch" VerticalContentAlignment="Center" 
                  FontSize="30" SelectedIndex="0" >
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Style="{StaticResource tbStyle}">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0}_____{1}_____{2}">
                                <Binding Path="Id"/>
                                <Binding Path="Name"/>
                                <Binding Path="ReleaseDate"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp35
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            List<Book> booksList = new List<Book>();
            for(int i=0;i<1000;i++)
            {
                booksList.Add(new Book()
                 {
                     Id = i + 1,
                     Name = $"Name_{i + 1}",
                     Author = $"Author_{i + 1}",
                     Concept = $"Concept_{i + 1}",
                     Header = $"Header_{i + 1}",
                     ISBN = $"ISBN_{i + 1}",
                     ReleaseDate = $"ReleaseDate_{DateTime.Now.AddYears(-(i % 1000)).ToString("yyyyMMddHHmmssffff")}",
                     Summary = $"Summary_{i + 1}",
                     Title = $"Title_{i + 1}",
                     Topic = $"Topic_{i + 1}"
                 });
            }
            cbx.ItemsSource = booksList;
        }
    }


    public class Book
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Author { get; set; }
        public int Chapter { get; set; }
        public string Concept { get; set; }
        public string Header { get; set; }
        public string ISBN { get; set; }
        public string ReleaseDate { get; set; }
        public string Summary { get; set; }
        public string Title { get; set; }
        public string Topic { get; set; }
    }
}

 

 

 

标签:multiple,Windows,Combobox,System,MainWindow,Loaded,using,properties
From: https://www.cnblogs.com/Fred1987/p/18112662

相关文章

  • Multiple Presentation
    ......
  • Wpf ComboBoxItem show multi fields
    <Windowx:Class="WpfApp28.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • 解决idea显示properties文件中文乱码
    解决idea显示properties文件中文乱码在项目中通常会遇到如下问题,突然properties文件中文就显示为\u5730等等这样类似的字符 解决方法如下1、File-》Settings-》FileEncodings,修改如下图中绿框标注的内容 2.点击Apply-》Ok3.修改完成后显示如果项目中存在多个propertie......
  • 【漏洞复现】MaxView系统dynamiccontent.properties接口处存在RCE漏洞
              免责声明:文章来源互联网收集整理,请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息或者工具而造成的任何直接或者间接的后果及损失,均由使用者本人负责,所产生的一切不良后果与文章作者无关。该文章仅供学习用途使用。      ......
  • IT15527: IN SPECIFIC TIMING CONDITIONS WITH MULTIPLE DB2READLOG API CALLERS(CDC,
    IT15527:INSPECIFICTIMINGCONDITIONSWITHMULTIPLEDB2READLOGAPICALLERS(CDC,ETC),"NOROOMFORRETRIEVEDLOG"occursindb2diag.loghttps://www.ibm.com/mysupport/s/defect/aCI0z000000TOfW/dt010963?language=en_USDescription 1.  Proble......
  • SpringBoot读取配置文件@Value || @ConfigurationProperties
    @Value注解优点:简单易用:@Value注解非常简单,适用于读取单个属性或简单的配置。灵活性:可以在任何Spring管理的bean中使用@Value注解,包括普通的bean、控制器、服务等。缺点:缺乏类型安全性:@Value注解不提供类型安全性检查,如果配置值的类型不匹配,只有在运行时才能发......
  • 【QT+QGIS跨平台编译】之八十二:【QGIS_Gui跨平台编译】—【错误处理:QgsExpressionCont
    文章目录一、未定义基类QgsExpressionContextGenerator二、错误处理一、未定义基类QgsExpressionContextGenerator报错信息二、错误处理第33行增加:#include"qgsexpressioncontextgenerator.h"......
  • 使用 LogProperties source generator 丰富日志
    Nuget包 Microsoft.Extensions.Telemetry.Abstractions包含的新的日志记录sourcegenerator,它支持使用[LogProperties]将整个对象作为State与日志一起记录。我将展示一种方法来控制如何使用[LogProperties]对象自动丰富日志。示例您可以使用日志sourcegenerator创建一个如下......
  • Cannot read properties of null (reading '$el')找出真凶
    Cannotreadpropertiesofnull(reading'$el')菜鸟,在vue3开发遇到的问题,百思不得其解,为什么会为null,先上代码大概的代码结构:<template><el-Dialogv-model="isLoading"><el-tableref="tableRef"><el-table-colum......
  • t05_Mysql_properties驱动配置
    mysql-properties#mysql5驱动com.mysql.jdbc.Driverspring.datasource.username=rootspring.datasource.password=rootspring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?useSSL=false&userUnicode=true&characterEncoding=utf-8spring.datasour......