Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: PropertyGrid: Create New Object?

$
0
0
I have a workaround for now until v2.4 is released.

In the Xaml, I define the Data Template as a resource with a key:
<DataTemplate x:Key="NewValueTemplate">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="{Binding Value}" />
        <Button x:Name="_button"
                Grid.Column="1"
                Content="Add New"
                Click="Button_Click"
                Visibility="{Binding Value, Converter={StaticResource MyConverter}}"/>
    </Grid>
</DataTemplate>
Then, in the code behind, I programmatically create a new EditorTemplateDefinition, set its TargetProperties, set its EditorTemplate to that resource, and add the EditorTemplateDefinition to the PropertyGrid's definitions:
EditorTemplateDefinition def = new EditorTemplateDefinition();
def.TargetProperties.Add(typeof(MyCustomClass));
def.EditingTemplate = (DataTemplate)FindResource("NewValueTemplate");
propGrid.EditorDefinitions.Add(def);
This technique does not break the designer. I added the template definition when the Loaded event of the application is fired.

Viewing all articles
Browse latest Browse all 2157

Trending Articles



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