wpf lookupedit 的使用

添加的引用
在这里插入图片描述

MainWindow.xaml
其中对编号列做了style

<Window x:Class="WpfApp1.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:WpfApp1"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
        xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" 
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <local:StatuToImage x:Key="test"/>
        <ControlTemplate x:Key="StatusType_PopupContentTemplate">
            
            <!--<dxg:GridControl x:Name="PART_GridControl" AutoExpandAllGroups="True">
                
                <dxg:GridControl.Columns>

                    <dxg:GridColumn Header="编号" FieldName="Id" />

                    <dxg:GridColumn Header="编号" FieldName="PId" />

                    <dxg:GridColumn Header="姓名" FieldName="Name" />


                    <dxg:GridColumn Header="编号" FieldName="Age" Width="60" FixedWidth="True" />
                    
                </dxg:GridControl.Columns>
                
                <dxg:GridControl.View>

                    <dxg:TableView
                          Name="View" 
                         ShowGroupedColumns="True" 
                         AutoWidth="True" 
                         AllowPerPixelScrolling="True" 
                         ScrollAnimationDuration="0" 
                         ShowAutoFilterRow="True" 
                         ShowTotalSummary="True" 
                         IsSynchronizedWithCurrentItem="False">
                    </dxg:TableView>
                    
                </dxg:GridControl.View>
                
            </dxg:GridControl>-->
            <dxg:GridControl Name="PART_GridControl">
                <dxg:GridControl.Columns>
                    <dxg:GridColumn Header="编码" FieldName="Id" ReadOnly="True">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">

                                    <Ellipse Fill="{Binding  RowData.Row.Id,Converter={StaticResource test}}" Height="8" Width="8" />
                                    <TextBlock  Text=" "/>

                                    <TextBlock Text="{Binding RowData.Row.Id}"/>
                                </StackPanel>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                    <!--<dxg:GridColumn Header="名称" FieldName="Name" ReadOnly="True"/>
                    <dxg:GridColumn Header="拼音码" FieldName="Pid" ReadOnly="True"/>-->
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AutoWidth="True" />
                </dxg:GridControl.View>
            </dxg:GridControl>
        </ControlTemplate>
    </Window.Resources>
    <StackPanel>
        <dxlc:LayoutControl Header="Header" UseLayoutRounding="True" Orientation="Vertical">
            <dxlc:LayoutGroup>
                <dxlc:LayoutItem x:Name="layoutControlItem_planType" Label="方案类型">
                    <dxg:LookUpEdit
                        ItemsSource="{Binding Path=personInfos}" 
                        DisplayMember="Name" 
                        ValueMember="Id" 
                        Name="lookUpEdit1"
                        
                        PopupContentTemplate="{StaticResource StatusType_PopupContentTemplate}"  IsTextEditable="False" TabIndex="12"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem x:Name="layoutControlItem_planType2" Label="方案类型">
                    <dxg:LookUpEdit
                        DisplayMember="Name" 
                        ValueMember="Id" 
                        Name="lookUpEdit2"
                        VerticalAlignment="Center"
                    ShowSizeGrip="True"
                    AutoPopulateColumns="False"
                    IsPopupAutoWidth="False"
                        PopupContentTemplate="{StaticResource StatusType_PopupContentTemplate}"  IsTextEditable="False" TabIndex="12"/>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>
        </dxlc:LayoutControl>
    </StackPanel>
</Window>


Model.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp1
{
    public class Model
    {
        public ObservableCollection<PersonInfo> personInfos { get; set; }
        public Model()
        {
            personInfos = new ObservableCollection<PersonInfo>()
            {
                //new PersonInfo{Id="1",PId="1",Name="1",Age=100,Address="1"},
                //new PersonInfo{Id="1",PId="1",Name="1",Age=100,Address="1"},
                //new PersonInfo{Id="1",PId="1",Name="1",Age=100,Address="1"},
                //new PersonInfo{Id="1",PId="1",Name="1",Age=100,Address="1"},
                 new PersonInfo{Id="完成",PId="1",Name="1",Age=100,Address="1"},
                new PersonInfo{Id="减班",PId="1",Name="1",Age=100,Address="1"},
                new PersonInfo{Id="计划",PId="1",Name="1",Age=100,Address="1"},
                new PersonInfo{Id="运营",PId="1",Name="1",Age=100,Address="1"},
            };
        }
    }
}


PersonInfo.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp1
{

    public class PersonInfo : DxslViewModelBase
    {
        #region 字段
        private string _id;
        private string _pId;
        private string _name;
        private int _age;
        private string _address;
        #endregion

        #region 属性
        /// <summary>
        /// 自增Id
        /// </summary>
        public string Id
        {
            get { return _id; }
            set
            {
                _id = value; NotifyPropertyChanged("Id");
            }
        }
        /// <summary>
        /// 父级Id
        /// </summary>
        public string PId
        {
            get { return _pId; }
            set { _pId = value; NotifyPropertyChanged("PId"); }
        }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }
        /// <summary>
        /// 年龄
        /// </summary>
        public int Age
        {
            get { return _age; }
            set { _age = value; NotifyPropertyChanged("Age"); }
        }
        /// <summary>
        /// 地址
        /// </summary>
        public string Address
        {
            get { return _address; }
            set { _address = value; NotifyPropertyChanged("Address"); }
        }
        #endregion

        #region 构造函数
        public PersonInfo()
        {

        }
        #endregion

        #region 方法

        #endregion
    }

    public class DxslViewModelBase : INotifyPropertyChanged
    {
        #region NotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// 属性通知
        /// </summary>
        /// <param name="property">属性名称</param>
        public void NotifyPropertyChanged(string property)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
        #endregion
    }

}

MainWindow.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 WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new Model();
        }
    }
}

value converter
StatuToImage

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfApp1
{
    //状态 转 方位 角
    //线路方向箭头转换
    public class StatuToImage : IValueConverter
    {
        //正向转换
        public object Convert(object Value, Type targetType, object parameter, CultureInfo culture)
        {

            if (Value == null)
                return Binding.DoNothing;

            SolidColorBrush bt;
            if (Value.ToString() == "计划")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffe032"));
            }
            else if (Value.ToString() == "待发")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#78c3f8"));
            }
            else if (Value.ToString() == "运营")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3487ef"));
            }
            else if (Value.ToString() == "完成")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8ad918"));
            }
            else if (Value.ToString() == "非计划")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9732"));
            }
            else if (Value.ToString() == "非待发")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9732"));
            }
            else if (Value.ToString() == "非执行")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9732"));
            }
            else if (Value.ToString() == "非完成")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9732"));
            }
            else if (Value.ToString() == "减班")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8e9294"));
            }
            else if (Value.ToString() == "删除")
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3232"));
            }
            else
            {
                bt = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
            }

            return bt;
        }


        //未找到
        public object ConvertBack(object Value, Type targetType, object parameter, CultureInfo culture)
        {
            return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
        }

    }


}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值