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

PropertyDefinition with RadNummericUpdown binding

1 Answer 69 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Gilbert van Veen
Top achievements
Rank 1
Gilbert van Veen asked on 02 Jul 2015, 01:56 PM

Hi,

I have an Observerable collection with objects. One of the properties is the Location information (RadMap info) of a hotspot.

The correct data is shown in the UpDown control but when I change the value (Up/Down arrows) the bound object (the location propery) is not changing?

The collection has INotifyChanged etc. but it isn't fired?

The XAML looks like this:

<telerik:PropertyDefinition Binding="{Binding Location.Latitude, Mode=TwoWay}" DisplayName="Latitude" Description="Location latitude" GroupName="Location" IsReadOnly="False" IsExpanded="True">
<telerik:PropertyDefinition.EditorTemplate>
<DataTemplate>
<telerik:RadNumericUpDown Value="{Binding Location.Latitude, Mode=TwoWay}" NumberDecimalDigits="12" Minimum="-99999" Maximum="9999" NumberDecimalSeparator="." />
</DataTemplate>
</telerik:PropertyDefinition.EditorTemplate>
</telerik:PropertyDefinition>

 Other fields of the object, f.i. the name of the hotspot is changing correctly.

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 07 Jul 2015, 12:55 PM
Hi Gilbert,

The binding of the Latitude and Longitude properties doesn't work because the Location object that expose them is a struct which means that you cannot set them directly. Moreover Location doesn't implement the INotifyPropertyChanged interface which means that the UI cannot listen for changes in its properties. 

In order to achieve the desired result you can expose Latitude and Longitude properties in the business object' class which is set as a data context of the hot spot. Then in the properties' setters you can update the Location property. Here is an example:
public class MyObject : ViewModelBase
{
    private Location location
    public Location Location
    {
        get { return this.location; }
        set
        {
            if (this.location != value)
            {
                this.location = value;
                OnPropertyChanged("Location");
            }
        }
    }
     
    private double latitude
    public double Latitude
    {
        get { return this.latitude; }
        set
        {
            if (this.latitude != value)
            {
                this.latitude = value;
                this.Location = new Location(this.latitude, this.Location.Longitude);
                OnPropertyChanged("Latitude");
            }
        }
    }
Please give this approach a try and let me know if it works for you. If not, can you please send me an isolated project that demonstrates your implementation. This will help me in better understanding your scenario and think of a more suitable approach for your case.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PropertyGrid
Asked by
Gilbert van Veen
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or