整理控件库
This commit is contained in:
@@ -7,8 +7,8 @@ using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Controls
|
||||
{
|
||||
[TemplatePart(Name = FilterTextBox, Type = typeof(WPFluent.Controls.TextBox))]
|
||||
[TemplatePart(Name = "PART_EditableTextBox", Type = typeof(WPFluent.Controls.TextBox))]
|
||||
[TemplatePart(Name = FilterTextBox, Type = typeof(System.Windows.Controls.TextBox))]
|
||||
[TemplatePart(Name = "PART_EditableTextBox", Type = typeof(System.Windows.Controls.TextBox))]
|
||||
public class ComboBoxEx : ComboBox
|
||||
{
|
||||
private const string FilterTextBox = "PART_FilterTextBox";
|
||||
@@ -45,7 +45,7 @@ namespace WPFluent.Controls
|
||||
new PropertyMetadata(true));
|
||||
|
||||
|
||||
private TextBox filterTextBox;
|
||||
private System.Windows.Controls.TextBox filterTextBox;
|
||||
private ICollectionView view;
|
||||
|
||||
static ComboBoxEx()
|
||||
@@ -62,14 +62,14 @@ namespace WPFluent.Controls
|
||||
/// <param name="e"></param>
|
||||
private void PART_FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if(filterTextBox == null)
|
||||
if (filterTextBox == null)
|
||||
return;
|
||||
|
||||
if(view != null)
|
||||
if (view != null)
|
||||
{
|
||||
view.Filter += (o) =>
|
||||
{
|
||||
if(o is string)
|
||||
if (o is string)
|
||||
{
|
||||
var value = o.ToString().ToLower();
|
||||
return value.IndexOf(filterTextBox.Text.ToLower(), StringComparison.Ordinal) != -1;
|
||||
@@ -78,7 +78,7 @@ namespace WPFluent.Controls
|
||||
{
|
||||
var obj = GetPropertyValue(o, DisplayMemberPath);
|
||||
//在xaml中写入Combobox时
|
||||
if(obj is ComboBoxItem item)
|
||||
if (obj is ComboBoxItem item)
|
||||
{
|
||||
obj = item.Content;
|
||||
}
|
||||
@@ -118,31 +118,33 @@ namespace WPFluent.Controls
|
||||
/// </summary>
|
||||
public static object GetPropertyValue(object obj, string path)
|
||||
{
|
||||
if(obj == null)
|
||||
if (obj == null)
|
||||
return string.Empty;
|
||||
|
||||
var result = obj;
|
||||
if(!string.IsNullOrEmpty(path))
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
var property = obj.GetType().GetProperty(path);
|
||||
if(property != null)
|
||||
if (property != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = property.GetValue(obj, null);
|
||||
return result;
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
var type = obj.GetType();
|
||||
var mInfo = type.GetMethod($"get_{path}");
|
||||
if(mInfo != null)
|
||||
if (mInfo != null)
|
||||
{
|
||||
result = mInfo.Invoke(obj, null);
|
||||
return result;
|
||||
}
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -158,13 +160,13 @@ namespace WPFluent.Controls
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
if(filterTextBox != null)
|
||||
if (filterTextBox != null)
|
||||
{
|
||||
filterTextBox.TextChanged -= PART_FilterTextBox_TextChanged;
|
||||
}
|
||||
|
||||
filterTextBox = GetTemplateChild(FilterTextBox) as TextBox;
|
||||
if(filterTextBox != null)
|
||||
filterTextBox = GetTemplateChild(FilterTextBox) as System.Windows.Controls.TextBox;
|
||||
if (filterTextBox != null)
|
||||
{
|
||||
filterTextBox.TextChanged += PART_FilterTextBox_TextChanged;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user