首页 > 其他分享 >WPF ListBox ListBox.ItemTemplate DataTemplate

WPF ListBox ListBox.ItemTemplate DataTemplate

时间:2024-06-08 20:22:39浏览次数:15  
标签:ItemTemplate Windows Media System using WPF ListBox MainWindow

<Window x:Class="WpfApp144.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:WpfApp144"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ListBox HorizontalAlignment="Stretch" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border Margin="2" Padding="4" BorderBrush="Black" BorderThickness="1">
                        <StackPanel Orientation="Horizontal" TextBlock.FontSize="16">
                            <TextBlock Foreground="Black" FontWeight="Bold" 
                                       Text="{Binding ProcessName,StringFormat='Name:\{0\}\     '}"/>
                            <TextBlock Margin="10,0,0,0" Foreground="Blue" 
                                       Text="{Binding Id,StringFormat='Id:\{0\}\    '}"/>
                            <TextBlock Margin="20,0,0,0" Foreground="Red"
                                       Text="{Binding Threads.Count,StringFormat='Threads Count:\{0\}'}"/>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="4" TextBlock.FontSize="20">
            
        </StackPanel>
    </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;
using System.Diagnostics;

namespace WpfApp144
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = Process.GetProcesses();
        }
    }
}

 

标签:ItemTemplate,Windows,Media,System,using,WPF,ListBox,MainWindow
From: https://www.cnblogs.com/Fred1987/p/18238907

相关文章

  • WPF master detail view
    <Windowx:Class="WpfApp143.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF RepeatButton
    是一个特殊的按钮,用于在用户长按或连续点击时重复执行特定动作。它通常用于需要重复执行某个操作的场景。常用属性描述Delay用于获取或设置RepeatButton在开始重复之前被按下时等待的时间(以毫秒为单位)。该值必须为非负数。Interval用于获取或设置开始重复后重复之......
  • WPF button mouseover background change color
    <Applicationx:Class="WpfApp142.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-nam......
  • 在WPF程序中如何实现主题,字体的切换
    在wpf程序中如何实现主题变换,首先我们需要先思考主题切换都更改了一些什么,无非就是字体颜色,背景颜色等一些资源当我们了解了主题变换的本质后就能够进一步去实现它,众所周知,在wpf中我们可以通过资源绑定的形式去实现颜色,字体,样式等一些资源绑定,在wpf中如果有相同的key通常会绑......
  • 【WPF】Dispatcher 与消息循环
    这一期的话题有点深奥,不过按照老周一向的作风,尽量讲一些人鬼都能懂的知识。咱们先来整个小活开开胃,这个小活其实老周在N年前写过水文的,常阅读老周水文的伙伴可能还记得。通常,咱们按照正常思路构建的应用程序,第一个启动的线程为主线程,而且还是UI线程(当然,WPF默认会创建辅助线......
  • WPF grid column resize via GridSpitter, when you can drag to enlarge or shrink t
    <Windowx:Class="WpfApp137.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF,图表控件
    开源代码地址:https://github.com/bearhanQ/WPFFramework;QQ群:332035933;<UserControlx:Class="WpfBootstrap.View.ChartsView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://......
  • wpf datagrid绑定行选中状态
    样式如下<DataGridMargin="0,6,0,0"HeadersVisibility="All"RowHeaderWidth="60"HorizontalScrollBarVisibility="Visible"AutoGenerateColumns="False"ItemsSource="{BindingDispl......
  • 界面控件Telerik UI for WPF中文教程 - 用RadSvgImage升级应用程序UI
    TelerikUIforWPF拥有超过100个控件来创建美观、高性能的桌面应用程序,同时还能快速构建企业级办公WPF应用程序。UIforWPF支持MVVM、触摸等,创建的应用程序可靠且结构良好,非常容易维护,其直观的API将无缝地集成VisualStudio工具箱中。TelerikUIforWPF中的RadSvgImage组件使......
  • WPF TranslateTransform +=deltaX +=deltaY
    <Windowx:Class="WpfApp136.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......