This is a migrated thread and some comments may be shown as answers.

Binding Problem in Custom Editor Template

4 Answers 200 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Mahmut
Top achievements
Rank 1
Mahmut asked on 02 Feb 2015, 01:18 PM
 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);
            }
 
}

4 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 02 Feb 2015, 05:57 PM
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.

 
0
Mahmut
Top achievements
Rank 1
answered on 03 Feb 2015, 08:16 AM
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);
    }
}
0
Mahmut
Top achievements
Rank 1
answered on 04 Feb 2015, 08:20 AM
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>
0
Ivan Ivanov
Telerik team
answered on 05 Feb 2015, 05:00 PM
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.

 
Tags
PropertyGrid
Asked by
Mahmut
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Mahmut
Top achievements
Rank 1
Share this question
or