WPF PropertyGrid 中自定义控件不响应ValueChanged事件。
以下是部分自定义控件:
public class MyZsmTextBoxEditor : Grid, ITypeEditorControl
{
public ITypeEditorControl Create()
{
MyZsmTextBoxEditor s = new MyZsmTextBoxEditor();
s.HorizontalAlignment = HorizontalAlignment.Stretch;
s.VerticalAlignment = VerticalAlignment.Stretch;
s.Height = 20;
ColumnDefinition c1 = new ColumnDefinition();
ColumnDefinition c2 = new ColumnDefinition();
c2.Width = new System.Windows.GridLength(17);
s.ColumnDefinitions.Add(c1);
s.ColumnDefinitions.Add(c2);
TextBox t = new TextBox();
t.HorizontalAlignment = HorizontalAlignment.Stretch;
t.VerticalAlignment = VerticalAlignment.Stretch;
t.TextWrapping = TextWrapping.NoWrap;
t.BorderThickness = new System.Windows.Thickness(0);
Grid.SetColumn(t, 0);
s.Children.Add(t);
C1.WPF.Toolbar.C1ToolbarButton b = new C1.WPF.Toolbar.C1ToolbarButton();
b.HorizontalAlignment = HorizontalAlignment.Stretch;
b.VerticalAlignment = VerticalAlignment.Stretch;
b.BorderThickness = new System.Windows.Thickness(0);
b.BorderBrush = System.Windows.Media.Brushes.Transparent;
b.Background = System.Windows.Media.Brushes.Transparent;
b.Content = "...";
b.HorizontalContentAlignment = HorizontalAlignment.Center;
b.VerticalContentAlignment = VerticalAlignment.Top;
b.Width = 15;
Grid.SetColumn(b, 1);
b.Click += new RoutedEventHandler((u, e) =>
{
Zsm zsm = new Zsm();
zsm.Text = t.Text;
if (true == zsm.ShowDialog())
{
t.Text = zsm.Text;
t.Focus();
}
});
s.Children.Add(b);
return s;
}
public bool Supports(PropertyAttribute Property)
{
return true;
}
public void Attach(PropertyAttribute property)
{
var binding = new System.Windows.Data.Binding(property.PropertyInfo.Name)
{
Mode = BindingMode.TwoWay,
Source = property.SelectedObject,
ValidatesOnExceptions = true
};
((TextBox)this.Children[0]).SetBinding(TextBox.TextProperty, binding);
}
public void Detach(PropertyAttribute property)
{
}
public event System.ComponentModel.PropertyChangedEventHandler ValueChanged;
}
可以给个相似的DEMO吗? |
|