Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: PropertyGrid: custom editor propertyItem.Instance is null

$
0
0
The customer editor code is as follows:
public class DefaultUomEditor : ITypeEditor
{
    private TextBox _tb;

    public DefaultUomEditor()
    {
        _tb = new TextBox();
    }

    public System.Windows.FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem)
    {
        propertyItem.IsReadOnly = true;
        //create the binding from the bound property item to the editor
        var _binding = new Binding("Value"); //bind to the Value property of the PropertyItem
        _binding.Source = propertyItem;
        _binding.ValidatesOnExceptions = true;
        _binding.ValidatesOnDataErrors = true;
        _binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
        BindingOperations.SetBinding(_tb, TextBox.TextProperty, _binding);

        if (propertyItem.Instance != null)
        {
            // do something...
        }

        return _tb;
    }

}
And the PropertyGrid.SelectedObject is bound to an object instance which has the following property defined as:
    [DisplayName("Default UOM")]
    [Editor(typeof(DefaultUomEditor), typeof(DefaultUomEditor))]        
    public string Uom
    {
        get { return this._uom; }
        internal set
        {
            this._uom = value;
            RaisePropertyChanged(() => this.Uom);
        }
    }

Viewing all articles
Browse latest Browse all 2157

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>