using PDF_Office.Model.From;
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 PDF_Office.CustomControl.Form
{
///
/// FormFieldCombox.xaml 的交互逻辑
/// 用于表单显示字段的下拉控件
///
public partial class FormFieldCombox : UserControl
{
public FormFieldCombox()
{
InitializeComponent();
InitCombox();
}
public FormFieldType Type
{
get { return (FormFieldType)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TypeProperty =
DependencyProperty.Register("Type", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible, FormFieldTypePropertyChanged));
private static void FormFieldTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as FormFieldCombox;
var type = (FormFieldType)e.NewValue;
if (control != null)
{
control.Combox.SelectedIndex = (int)type;
}
}
public FormFieldType SetType
{
get { return (FormFieldType)GetValue(SetTypeProperty); }
set { SetValue(SetTypeProperty, value); }
}
// Using a DependencyProperty as the backing store for SetType. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SetTypeProperty =
DependencyProperty.Register("SetType", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible,(d,e)=> {
(d as FormFieldCombox).SetIndexBySetType((FormFieldType)e.NewValue);
}));
///
/// 根据settype 设置combox索引
///
private void SetIndexBySetType(FormFieldType type)
{
Combox.SelectedIndex=(int)type;
}
private void InitCombox()
{
List list = new List();
list.Add("可见");
list.Add("隐藏");
list.Add("可见但不可打印");
list.Add("隐藏但可打印");
Combox.ItemsSource = list;
}
private void Combox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Type = (FormFieldType)Combox.SelectedIndex;
}
}
}