資源簡(jiǎn)介
WPF-省市縣3級(jí)聯(lián)動(dòng),非專業(yè)WPF/C#人員,只是在網(wǎng)上沒找到特別合適的,所以自己做了一個(gè)。
代碼片段和文件信息
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?!
評(píng)論
共有 條評(píng)論