基本信息
源码名称:WPF属性窗口例子源码
源码大小:0.11M
文件格式:.rar
开发语言:C#
更新时间:2015-03-03
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
属性窗口源码
public partial class MainWindow : Window
{
private Person Person = new Person();
private Vehicle Vehicle1 = new Vehicle();
private Vehicle Vehicle2 = new Vehicle();
private Place Place = new Place();
// names must match the data members
private object[] ItemArray = { "Person", "Vehicle1", "Vehicle2", "Place" };
public MainWindow()
{
InitializeComponent();
this.Vehicle1.PropertyChanged = new System.ComponentModel.PropertyChangedEventHandler(Vehicle_PropertyChanged);
this.Vehicle2.PropertyChanged = new System.ComponentModel.PropertyChangedEventHandler(Vehicle_PropertyChanged);
this.Radio3.IsChecked = true;
this.NoSelection_Click(this, null);
}
// Special handling for vehicle type change
void Vehicle_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
this.PropertyGrid1.RefreshPropertyList();
}
private void SingleSelect_Click(object sender, RoutedEventArgs e)
{
this.ItemList.ItemTemplate = this.Resources["RadioButtons"] as DataTemplate;
this.ItemList.ItemsSource = this.ItemArray;
this.PropertyGrid1.SelectedObject = null;
}
private void MultiSelect_Click(object sender, RoutedEventArgs e)
{
this.ItemList.ItemTemplate = this.Resources["CheckBoxes"] as DataTemplate;
this.ItemList.ItemsSource = this.ItemArray;
this.PropertyGrid1.SelectedObject = null;
}
private void NoSelection_Click(object sender, RoutedEventArgs e)
{
this.ItemList.ItemTemplate = null;
this.ItemList.ItemsSource = new string[] { "(none)" };
this.PropertyGrid1.SelectedObject = null;
}
private void Item_Checked(object sender, RoutedEventArgs e)
{
if (e.Source is RadioButton)
{
object selected = this.GetType().GetField((e.Source as RadioButton).Content.ToString(),
System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this);
this.PropertyGrid1.SelectedObject = selected;
}
else if (e.Source is CheckBox && this.Radio2.IsChecked.GetValueOrDefault())
{
ArrayList selected = new ArrayList();
for (int i = 0; i < ItemList.Items.Count; i )
{
ContentPresenter container = ItemList.ItemContainerGenerator.ContainerFromIndex(i) as ContentPresenter;
DataTemplate dataTemplate = container.ContentTemplate;
CheckBox chk = (CheckBox)dataTemplate.FindName("chk", container);
if (chk.IsChecked.GetValueOrDefault())
{
object item = this.GetType().GetField(chk.Content.ToString(),
System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this);
selected.Add(item);
}
}
this.PropertyGrid1.SelectedObjects = selected.ToArray();
}
}
private void ShowDescrip_Click(object sender, RoutedEventArgs e)
{
this.PropertyGrid1.HelpVisible = !this.PropertyGrid1.HelpVisible;
}
private void ShowToolbar_Click(object sender, RoutedEventArgs e)
{
this.PropertyGrid1.ToolbarVisible = !this.PropertyGrid1.ToolbarVisible;
}
}