河南网站建设培训,帮别人发广告赚钱平台,网络推广公司哪家好,免费行情网站排名固定最简步骤#xff0c;包括
XAML#xff1a;
题头里引入命名空间
标题下面引入类
combobox绑定资源属性和选择属性#xff0c;block则绑定和combobox一样的选择属性
C##xff1a;
通知的类#xff0c;及对应固定的任务
引入字段
引入属性
其中资源是只读的
选…固定最简步骤包括
XAML
题头里引入命名空间
标题下面引入类
combobox绑定资源属性和选择属性block则绑定和combobox一样的选择属性
C#
通知的类及对应固定的任务
引入字段
引入属性
其中资源是只读的
选择属性是单触发必须要加nameof
属性
block指向box的属性 这是最简形式
Window x:Class绑定类型2_combobox.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:MainWindow_ViewModelmc:IgnorabledTitleMainWindow Height450 Width800Window.DataContextlocal:MainWindowViewModel//Window.DataContextGridComboBox HorizontalAlignmentLeft Margin378,142,0,0 VerticalAlignmentTop Width120 ItemsSource{Binding Item_source} SelectedItem{Binding SelectedItem, ModeTwoWay}/TextBlock HorizontalAlignmentLeft Margin378,187,0,0 TextWrappingWrap VerticalAlignmentTop Text{Binding SelectedItem}//Grid
/Windowusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Web;namespace MainWindow_ViewModel
{class MainWindowViewModel:INotifyPropertyChanged{private string[] item_source { 6dB/oct, 12dB/oct, 18dB/oct, 24dB/oct, 30dB/oct, 36dB/oct, 42dB/oct, 48dB/oct };private string selectedItem;public string[] Item_source{get { return item_source; }}public string SelectedItem{get { return selectedItem; }set{selectedItem value;OnPropertyChanged(nameof(SelectedItem));}}//固定public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged([CallerMemberName] string propertyName null){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}}
}也可以block绑定单独一个属性像之前那样 public string SelectedItem{get { return selectedItem; }set{selectedItem value;OnPropertyChanged(nameof(SelectedItem));OnPropertyChanged(nameof(SelectedItemDisplay));}}public string SelectedItemDisplay SelectedItem; ComboBox HorizontalAlignmentLeft Margin378,142,0,0 VerticalAlignmentTop Width120 ItemsSource{Binding Item_source} SelectedItem{Binding SelectedItem, ModeTwoWay}/TextBlock HorizontalAlignmentLeft Margin378,187,0,0 TextWrappingWrap VerticalAlignmentTop Text{Binding SelectedItemDisplay}/