Changing value dynamically with template problem

2 posts, 0 answers
  1. Alain
    Alain avatar
    239 posts
    Member since:
    Aug 2013

    Posted 08 Feb Link to this post



    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">
                            <Grid Margin="0,0,2,0">
                                    <ColumnDefinition Width="Auto"/>
                                <TextBox Text="{Binding SourceFile}" Grid.Column="0"/>
                                <Button Content="..." Width="25" Height="25" Grid.Column="1" Click="SelectFileClick"/>
                    <!-- More templates here -->


        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...




  2. Dilyan Traykov
    Dilyan Traykov avatar
    334 posts

    Posted 11 Feb Link to this post

    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.

    Dilyan Traykov
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top