Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: EditorComboBoxDefinition ItemsSource [21116]

$
0
0
Hi,

I am trying to use the Propertygrid (Plus version) to build a dynamic properties list.
I have been looking at the Custom Properties List examples but I am struggling to populate a combobox
with a list of string values built at runtime. I can't use an enum as I don't know the available values until a database is read.

I'm using MVVM and have bound my view to a view model.
I have created a new test class that contains a List of available strings and the currently selected string.
I am binding the test class MyData to the propertygrid properties source as in the example

```
public class ObjectWithNames
{
public ObservableCollection<string> Names { get; set; }
public string ObjectName { get; set; }

public override string ToString()
{
return ObjectName;
}
}

public class MyData
{

public MyData(string name, object value, string category)
{
this.MyName = name;
this.MyValue = value;
this.Category = category;

}
public MyData(string name, object value)
{
this.MyName = name;
this.MyValue = value;
this.Category = "Misc";

}


public string Category { get; set; }
public string MyName { get; set; }
public object MyValue { get; set; }

}
```

In My View Model I have a list of MyData objects

```
public ObservableCollection<object> SelectedLru
{
get { return _properties; }

}

private void BuildDummyProperties()
{
...
_properties.Add(new MyData("TestNames", (ObjectWithNames)new ObjectWithNames() { ObjectName = "Option 1", Names = new ObservableCollection<string>() { "Option 1", "Option 2" } }));
...
}
```


My View binds the properties source to the list of mydata objects.
I then set the xctk:EditorComboBoxDefinition TargetProperties to my test class ObjectWithNames.


```
<xctk:PropertyGrid x:Name="propertyGrid" Grid.Row="2"
PropertiesSource="{Binding SelectedLru}"
PropertyNameBinding="{Binding MyName}"
PropertyValueBinding="{Binding MyValue}">

<xctk:PropertyGrid.CategoryGroupDescription>
<PropertyGroupDescription PropertyName="Category"/>
</xctk:PropertyGrid.CategoryGroupDescription>

<xctk:PropertyGrid.Resources>
<local:MyConverter x:Key="myConverter"/>
</xctk:PropertyGrid.Resources>
<xctk:PropertyGrid.EditorDefinitions>



<xctk:EditorComboBoxDefinition TargetProperties="{x:Type local:ObjectWithNames}"
ItemsSource="{Binding MyValue.Names}
SelectedItemBinding="{Binding MyValue, Converter={StaticResource myConverter}" />


</xctk:PropertyGrid.EditorDefinitions>


</xctk:PropertyGrid>
```

This all works when the combobox items source is a static resource as in the example
```

<x:Array x:Key="comboSource1" Type="s:String" >
<s:String>String Value 1</s:String>
<s:String>String Value 2</s:String>
<s:String>String Value 3</s:String>
</x:Array>
```

However I am struggling to work out how to set the items source to the collection of strings in the ObjectWithNames class. I have tried using a Converter to see what is going on but that never seems to be called.

```
<xctk:EditorComboBoxDefinition TargetProperties="{x:Type local:ObjectWithNames}"
ItemsSource="{Binding MyValue, Converter={StaticResource myValuesConverter}"
SelectedItemBinding="{Binding MyValue, Converter={StaticResource myConverter}"
```

Any ideas would be appreciated. Is there an easier way to build the combo box items dynamically or at runtime?

Cheers
Jonathan
Comments: ** Comment from web user: jwoolcock **

Thank you that has addressed the issue for a dynamic combo box.
I am having a similar issue configuring the EditorIntegerUpDownDefinition at runtime.

I am binding the following object to the property grid.
The value is the current value, with the minimum, maximum and step values read from a database.

```
public class MinMaxParameter
{
public int Minimum { get; set; }
public int Maximum { get; set; }
public int Step { get; set; }
public int Value { get; set; }
}
```

When I set the min,max and step to values to actual values it works

```
<xctk:EditorIntegerUpDownDefinition TargetProperties="{x:Type local:MinMaxParameter}"
Binding="{Binding Path=PropertyValue.Value}"
Maximum="100" Step="10"
Minimum="10"
>


```
However when I set them to the bound values it doesn't work.


```
<xctk:EditorIntegerUpDownDefinition TargetProperties="{x:Type local:MinMaxParameter}"
Binding="{Binding Path=PropertyValue.Value}"
Maximum="{Binding Path=PropertyValue.Maximum}"
Minimum="{Binding Path=PropertyValue.Minimum}">
```


Viewing all articles
Browse latest Browse all 4964

Trending Articles



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