Consider my DataTemplateSelector below. I want all my RadPropertyGrid to have this particular editor for all string properties. This implies a problem when binding to the property in XAML - since the property name is unknown! How can I get this working?
My initial thought was to map Path to the property so that I can later bind to the Path instead of a specified property name. Ideas?
Binding becomes a problem since the property name is unknown:
My initial thought was to map Path to the property so that I can later bind to the Path instead of a specified property name. Ideas?
public class MyPropertyGridDataTemplateSelector : DataTemplateSelector{ public override DataTemplate SelectTemplate(object item, DependencyObject container) { var pd = item as PropertyDefinition; if (pd != null && pd.SourceProperty.PropertyType == typeof(string)) { /* Something like this? pd.Binding = new Binding { Path = new PropertyPath(pd.SourceProperty.Name), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus }; */ return FilePathDataTemplate; } return null; } public DataTemplate FilePathDataTemplate { get; set; }}Binding becomes a problem since the property name is unknown:
<local:MyPropertyGridDataTemplateSelector x:Key="dataTemplateSelector"> <local:MyPropertyGridDataTemplateSelector.FilePathDataTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <!-- This is where the problem begin... --> <TextBox Text="{Binding Path}" Grid.Column="0" /> <Button Content="..." Width="25" Height="25" Grid.Column="1" Command="{Binding DataContext.OpenCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" CommandParameter="{Binding Path}" /> </Grid> </DataTemplate> </local:MyPropertyGridDataTemplateSelector.FilePathDataTemplate> </local:MyPropertyGridDataTemplateSelector>