wpf propertyGrid

2019-05-06 05:19发布

问题:

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

回答1:

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!



回答2:

I know this is an old post, but there is a new PropertyGrid on the block and it is the most functional and feature rich one out there. Oh and it's FREE!

http://wpftoolkit.codeplex.com/



回答3:

For whoever is interested, I've started a simple - but I hope useful - free and open source PropertyGrid project for WPF.

The source is available here: https://github.com/SoftFluent/SoftFluent.Windows and there is also a nuget package here: https://www.nuget.org/packages/SoftFluent.Windows.

It has no dependencies, but requires .NET 4 as it uses WPF's .NET 4 DataGrid class.



回答4:

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" />