wpf propertyGrid

Ash*_*sha 4 c# wpf propertygrid

我的WPF应用程序需要一个propertyGrid.经过大量的搜索,我发现这个 我添加了程序集(exe文件),当我将propertyGrid添加到我的表单时,我运行它,我无法在表单中看到它.xaml代码:

<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>
Run Code Online (Sandbox Code Playgroud)

代码背后:

private void btn_Click(object sender, RoutedEventArgs e)
        {
            property.Instance = btn;
        }
Run Code Online (Sandbox Code Playgroud)

请帮助我找出为什么它不可见

Bri*_*nas 17

我知道这是一个旧帖子,但是块上有一个新的PropertyGrid,它是功能最强大,功能最丰富的一个.哦,它是免费的!

http://wpftoolkit.codeplex.com/

在此输入图像描述

  • 该存档已迁移到 https://github.com/xceedsoftware/wpftoolkit 并且不再免费(它们需要商业许可证)。 (2认同)

Ray*_*rns 7

这是由于WPFPropertyGrid代码中的错误.

从他的ThemeInfoAttribute看来,该代码的作者打算使用泛型主题,但他错误地将他的资源放在文件"Themes/default.xaml"而不是"Themes/generic.xaml"中.因此,资源不会自动加载.他通过从App.xaml手动加载资源来解决这个问题.

当你从你的.exe引用他的.exe时,他的App.xaml没有加载,所以他的解决方法没有被激活.

最好的解决方案是将原始代码中的文件名更正为"Themes/generic.xaml".如果无法做到这一点,那么第二好的解决方案是手动加载App.xaml中的资源:

  <Application.Resources>

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

  </Application.Resources>
Run Code Online (Sandbox Code Playgroud)

或者如果您愿意,可以将其放在窗口中的标签中.

请注意,上述XAML假定将使用其他资源,因此需要合并.如果没有,您可以跳过创建单独字典和合并的步骤,而只需将WPGDemo字典设置为您的应用程序或窗口字典.

祝你有美好的一天!