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

Changing value dynamically with template problem

1 Answer 13 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Christie Admin
Top achievements
Rank 1
Christie Admin asked on 08 Feb 2016, 05:35 PM

Hi,

 

in my XAML I use the following TemplateSelector to have a button beside my "SourceFile" property to open a FileDialog to select a filename:

            <local:PropertyGridTemplateSelector x:Key="dataTemplateSelector">
                <local:PropertyGridTemplateSelector.SourceFilePropertyTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,2,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBox Text="{Binding SourceFile}" Grid.Column="0"/>
                            <Button Content="..." Width="25" Height="25" Grid.Column="1" Click="SelectFileClick"/>
                        </Grid>
                    </DataTemplate>
                </local:PropertyGridTemplateSelector.SourceFilePropertyTemplate>
                <!-- More templates here -->
            </local:PropertyGridTemplateSelector>

 

    public class PropertyGridTemplateSelector : DataTemplateSelector 
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            PropertyDefinition dpi = item as PropertyDefinition;
            
            if (dpi.DisplayName == "SourceFile")
            {
                return SourceFilePropertyTemplate;
            }

            return null;
        }

        public DataTemplate SourceFilePropertyTemplate { get; set; }
    }

 

when I select a file through my file dialog,I want to update the recontrol to reflect the selection I made in my file dialog...

 

Thank's

Alain

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 11 Feb 2016, 03:45 PM
Hello Alain,

I've attached a sample project to show you how to achieve the desired behavior.

What I've done is created an Avatar class with a single SourceFile property, which implements the INotifyPropertyChanged. Then I set the SourceFile property of the item to the SafeFileName of the selected file, which triggers the OnPropertyChanged event, which in turn updates the value of the textbox.

Let me know whether this works for you. Feel free to approach me with any further questions you might have.

Regards,
Dilyan Traykov
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
Christie Admin
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or