views:

829

answers:

2

Hi all, I need a propertyGrid for my WPF application . after lots of searches I have found this I have added the assembly (exe file) when I add the propertyGrid to my form and I run it I can't see it in the form . xaml code :

<Window x:Class="propertyGridTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpg="clr-namespace:Deepforest.WPF.Controls;assembly=WPGDemo"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Button x:Name="btn" Click="btn_Click" Height="35.5" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="55"></Button>
        <wpg:PropertyGrid x:Name="property" Width="100" Height="100"> </wpg:PropertyGrid>
    </Grid>
</Window>

code behind :

private void btn_Click(object sender, RoutedEventArgs e)
        {
            property.Instance = btn;
        }

please help me to find out why it's not visible

A: 

Did you read the documentation at the download page?

WPF Property Grid Download Page

It seems like you have to reference the property you want edited, like this for example:

<wpg:PropertyGrid Width="550" Height="550" Instance="{Binding ElementName=button}" />
<Button x:Name="button" Content="Click" />
Jark
yes my friend I have read it, but it didn't help . the problem is that when I put the control in my form It seems that the control is not visible !thank you
Asha
+4  A: 

This is due to a bug in the WPFPropertyGrid code.

It appears from his ThemeInfoAttribute that the author of that code intended to use a generic theme, but he mistakenly put his resources in the file "Themes/default.xaml" instead of "Themes/generic.xaml". Because of this the resources were not automatically loaded. He worked around the bug by loading the resources manually from his App.xaml.

When you referenced his .exe from yours, his App.xaml wasn't loaded so his workaround wasn't activated.

The best solution is to correct the filename in the original code to "Themes/generic.xaml". If that is not possible, the second-best solution is to manually load the resources from your App.xaml:

  <Application.Resources>

    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/WPGDemo;Component/Themes/Default.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

  </Application.Resources>

Or if you prefer, you can put this in a tag in your window.

Note that the above XAML assumes other resources will be used so a merge will be necessary. If not, you can skip the steps of creating a seperate dictionary and merging, and instead just set the WPGDemo dictionary as your App or Window dictionary.

Have a great day!

Ray Burns