Binding Problem in Custom Editor Template

5 posts, 0 answers
  1. Mahmut
    Mahmut avatar
    22 posts
    Member since:
    Nov 2014

    Posted 02 Feb 2015 Link to this post

     Hi,
    I tried a method in a similar thread for custom ComboBox editor. I can see NodeTypes in the ComboBox element. But when select the item, value can not assign to target value. CheckConverter is just created to check binding value, and converter not rising.

    Thanks in advance.

    public class Node : ObservableObject
    {
            protected int nodeType;
     
            public int NodeType
            {
                get { return nodeType; }
                set { nodeType= value; RaisePropertyChanged(() => NodeType ); }
            }
       }

     
    <DataTemplate x:Key="NodeTypeTemplate">
     
            <telerikRad:RadComboBox ItemsSource="{Binding
    Source={x:Static helpers:ItemViewFacade.NodeTypes}}"
     
                                     SelectedValue="{Binding NodeType,Converter={StaticResource
    CheckConverter}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
     
                                     SelectedValuePath="Value"
     
                                     DisplayMemberPath="Header"
     
                                     Margin="0">
     
            </telerikRad:RadComboBox>
     
        </DataTemplate>

     

     
    private void radPropertyGrid1_AutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
     {
                if(e.PropertyDefinition.DisplayName == "NodeType")
                {
                    var templateName = string.Format("{0}Template",e.PropertyDefinition.DisplayName);
     
                    e.PropertyDefinition.EditorTemplate = templateSelector.GetTemplate(templateName);
                }
     
    }
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 02 Feb 2015 Link to this post

    Hello,

    Can you please confirm whether you have BIndingExpressionPath errors in the output window at run-time? Generally, they are thrown when binding is impossible during to incorrect source, or path. You can also send us some more information about your data model? What is the relation between the Value and NodeType properties?
    As a side note, you can use a DataTemplateSelector, just by assigning the EditorTemplateSelectorProperty, avoiding the logic that you are executing on AutogeneratingPropertyDefinition.

    Regards,
    Ivan Ivanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mahmut
    Mahmut avatar
    22 posts
    Member since:
    Nov 2014

    Posted 03 Feb 2015 in reply to Ivan Ivanov Link to this post

    Thanks for your response Ivan and you right., my mistake, so you can see my other data model in below. Actually I noticed that I can use EditorTemplateSelector after trying the first method. Both of them has same logic, therefore changing is not so hard. Thanks for information anyway, but firstly I solve the binding issue. When I assign a value(which is type of Node) to Item Property of PropertyGrid, I can see Node Types. Mixing, Temp etc., like I said before. Only problem is that NodeType in Node Object is not updated.
    (if there is any mistake in my English, sorry about that)

    public class ViewItem<TValue> : ObservableObject
    {
        string header;
        TValue value;
     
        public string Header
        {
            get { return header; }
            set { header = value; RaisePropertyChanged(() => Header); }
        }
     
        public TValue Value
        {
            get
            {
                if (this.value == null)
                    this.value = default(TValue);
                return this.value;
            }
            set
            {
                this.value = value;
                RaisePropertyChanged(() => Value);
            }
        }
     
        public ViewItem(string header, TValue value)
        {
            this.header = header;
            this.value = value;
        }
    }
     
     
     
    public class ItemViewFacade
    {
        private static ObservableCollection<ViewItem<int>> nodeTypes;
             
        public static ObservableCollection<ViewItem<int>> NodeTypes
        {
           get
           {
                if(nodeTypes== null)
                    nodeTypes = GetNodeTypes();
                return nodeTypes;
            }
        }
     
        public static ObservableCollection<ViewItem<int>> GetNodeTypes()
        {
            var collection = new ObservableCollection<ViewItem<int>>();
            collection.Add(GetItem<int>("Mixing", 1));
            collection.Add(GetItem<int>("Partial", 2));
            collection.Add(GetItem<int>("Temp", 3));
            return collection;
        }
     
        public static ViewItem<TValue> GetItem<TValue>(string header, TValue value)
        {
            return new ViewItem<TValue>(header, value);
        }
    }
  5. Mahmut
    Mahmut avatar
    22 posts
    Member since:
    Nov 2014

    Posted 04 Feb 2015 Link to this post

    I solved the problem. Target of my DataTemplate is not my object. It is PropertySetViewModel, so It was not working, because I was trying to bind property in my object. PropertySetViewModel has property , which named CurrentPropertySet. I think it is Dictionary, and it maps property name to property value. I want to share, because he/she can easily find the solution, if someone can have same problem. Template example is below.

    Thanks for your help.

    <DataTemplate x:Key="NodeTypeTemplate">
            <telerikRad:RadComboBox ItemsSource="{Binding
    Source={x:Static helpers:ItemViewFacade.NodeTypes}}"
                                     SelectedValue="{Binding Path=CurrentPropertySet[NodeType], Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                     SelectedValuePath="Value"
                                     DisplayMemberPath="Header"
                                     Margin="0">
            </telerikRad:RadComboBox>
      
        </DataTemplate>
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 05 Feb 2015 Link to this post

    Hello,

    I am glad to hear that you managed to solve this problem. Thank you for sharing your experience through the community.

    Regards,
    Ivan Ivanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready