• 大小: 2KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: 省市县  WPF  

资源简介

WPF-省市县3级联动,非专业WPF/C#人员,只是在网上没找到特别合适的,所以自己做了一个。

资源截图

代码片段和文件信息

using Baolaitong.baseService.ViewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Baolaitong.WpfShellPlugin.Content
{
    /// 
    /// AreaSelect.xaml 的交互逻辑
    /// 

    public partial class AreaSelect : UserControl INotifyPropertyChanged
    {

        private IList _provinces = new List();

        public static readonly DependencyProperty ProvinceProperty = DependencyProperty.Register(“Province“ typeof(string) typeof(AreaSelect) new frameworkPropertymetadata(string.Empty));
        public static readonly DependencyProperty CityProperty = DependencyProperty.Register(“City“ typeof(string) typeof(AreaSelect) new frameworkPropertymetadata(string.Empty));
        public static readonly DependencyProperty CountyProperty = DependencyProperty.Register(“County“ typeof(string) typeof(AreaSelect) new frameworkPropertymetadata(string.Empty));


        public IList Provinces
        {
            get
            {
                return _provinces;
            }
            set
            {
                _provinces.Clear();
                if (value != null)
                {
                    foreach (Province province in value)
                    {
                        _provinces.Add(province);
                    }
                }
            }
        }
        
        public AreaSelect()
        {
            InitializeComponent();
            this.Content.DataContext = this;
            this.PropertyChanged += SelectedArea_PropertyChanged;
        }

        private void SelectedArea_PropertyChanged(object sender PropertyChangedEventArgs e)
        {
            Console.WriteLine(Province + “ “ + City + “ “ + County);
        }


        private string _province;
        private string _city;
        private string _county;

        public string Province
        {
            get { return _province; }
            set
            {
                _province = value;
                _city = string.Empty;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this new PropertyChangedEventArgs(“Province“));
                }
            }
        }
        public string City
        {
            get { return _city; }
            set
            {
                _city = value;
                _county = string.Empty;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this new PropertyChangedEventArgs(“City“));
                }
            }
        }
        public string County
        {
            get { return _county; }
            set
            {
                _county = value;
                if (PropertyChanged !

评论

共有 条评论