wpf propertyGrid [英] wpf propertyGrid

查看:111
本文介绍了wpf propertyGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WPF应用程序需要一个propertyGrid.经过大量搜索后,我发现当我将propertyGrid添加到窗体中并运行它时,我已经添加了程序集(exe文件),但在窗体中看不到它.xaml代码:

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>

后面的代码:

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

请帮助我找出不可见的原因

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

推荐答案

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

This is due to a bug in the WPFPropertyGrid code.

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

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.

当您从自己的.exe文件中引用他的.exe时,未加载他的App.xaml,因此未激活他的解决方法.

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

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

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.

请注意,以上XAML假定将使用其他资源,因此有必要进行合并.如果没有,您可以跳过创建单独的词典和合并的步骤,而只需将WPGDemo词典设置为您的App或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.

祝你有美好的一天!

这篇关于wpf propertyGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆