|
@@ -164,6 +164,17 @@ namespace PDF_Office.CustomControl.CompositeControl
|
|
|
set { SetValue(SelectedItemsProperty, value); }
|
|
|
}
|
|
|
|
|
|
+ //外部需要下拉框都不选中时,true为不选中,false为正常选中
|
|
|
+ public bool IsSelectedEmpty
|
|
|
+ {
|
|
|
+ get { return (bool)GetValue(IsSelectedEmptyProperty); }
|
|
|
+ set { SetValue(IsSelectedEmptyProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty IsSelectedEmptyProperty =
|
|
|
+ DependencyProperty.Register("IsSelectedEmpty", typeof(bool), typeof(CustomComboControl), new PropertyMetadata(false, IsSelectedEmptyPropertyChanged));
|
|
|
+
|
|
|
+
|
|
|
public static readonly DependencyProperty SelectedItemsProperty =
|
|
|
DependencyProperty.Register("SelectedItems", typeof(ComboDataItem), typeof(CustomComboControl), new PropertyMetadata(null, SelectedItemsPropertyChanged));
|
|
|
|
|
@@ -184,11 +195,28 @@ namespace PDF_Office.CustomControl.CompositeControl
|
|
|
DependencyProperty.Register("IsValueContent", typeof(bool), typeof(CustomComboControl), new PropertyMetadata(false));
|
|
|
|
|
|
//集合绑定下拉框 SelectedItems触发属性
|
|
|
+ private static void IsSelectedEmptyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
+ {
|
|
|
+ var control = d as CustomComboControl;
|
|
|
+ var isSelectedEmpty = (bool)e.NewValue;
|
|
|
+ if(control != null)
|
|
|
+ {
|
|
|
+ if(isSelectedEmpty)
|
|
|
+ {
|
|
|
+ control.comBox.SelectedItem = null;
|
|
|
+ control.SelectedIndex = -1;
|
|
|
+ control.SelectedItems = null;
|
|
|
+ control.title.Text = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private static void SelectedItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
{
|
|
|
var control = d as CustomComboControl;
|
|
|
var selectedItems = (ComboDataItem)e.NewValue;
|
|
|
- if (control != null & selectedItems != null)
|
|
|
+ if (control != null & selectedItems != null && control.IsSelectedEmpty == false)
|
|
|
{
|
|
|
if(control.comBox.Items != null && control.comBox.Items.Count > 0)
|
|
|
{
|
|
@@ -237,7 +265,7 @@ namespace PDF_Office.CustomControl.CompositeControl
|
|
|
{
|
|
|
var control = d as CustomComboControl;
|
|
|
var itemsource = (List<ComboDataItem>)e.NewValue;
|
|
|
- if (control != null)
|
|
|
+ if (control != null && control.IsSelectedEmpty == false)
|
|
|
{
|
|
|
control.SelectedIndex = -1;
|
|
|
control.comBox.ItemsSource = itemsource;
|
|
@@ -251,12 +279,12 @@ namespace PDF_Office.CustomControl.CompositeControl
|
|
|
{
|
|
|
var control = d as CustomComboControl;
|
|
|
var selectedIndex = (int)e.NewValue;
|
|
|
- if (control != null)
|
|
|
+ if (control != null && control.IsSelectedEmpty == false)
|
|
|
{
|
|
|
if(control.comBox.Items != null && control.comBox.Items.Count > 0 && selectedIndex != -1)
|
|
|
{
|
|
|
control.comBox.SelectedIndex = selectedIndex;
|
|
|
- if (control.comBox.SelectedItem != null)
|
|
|
+ if (control.comBox.SelectedItem != null )
|
|
|
control.SelectedItems = (ComboDataItem)control.comBox.SelectedItem;
|
|
|
else
|
|
|
control.SelectedItems = null;
|
|
@@ -273,7 +301,8 @@ namespace PDF_Office.CustomControl.CompositeControl
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- title.Text = Items[SelectedIndex].Content;
|
|
|
+ if (IsSelectedEmpty == false)
|
|
|
+ title.Text = Items[SelectedIndex].Content;
|
|
|
}
|
|
|
}
|
|
|
}
|