2009-11-02 79 views
3

我需要一個propertyGrid,用於我的WPF應用程序。經過大量搜索,我發現this 我添加了組件(exe文件),當我將propertyGrid添加到我的窗體並運行它時,我無法在窗體中看到它。 XAML代碼:背後wpf propertyGrid

<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; 
     } 

請幫我找出爲什麼它不可見

回答

7

這是由於WPFPropertyGrid代碼中的錯誤。

從他的ThemeInfoAttribute看來,該代碼的作者打算使用通用主題,但他錯誤地將他的資源放在「Themes/default.xaml」文件中而不是「Themes/generic.xaml」中。因此,資源不會自動加載。他通過從他的App.xaml手動加載資源來解決bug。

當你從你的引用他的.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> 

或者,如果你願意,你可以在你的窗戶把這個標籤。

請注意,上述XAML假定將使用其他資源,因此合併將是必要的。如果沒有,您可以跳過創建單獨字典和合並的步驟,而只需將WPGDemo字典設置爲App或Window字典。

祝您有美好的一天!

-2

你閱讀的下載頁面的文檔?

WPF Property Grid Download Page

好像你必須引用您希望編輯的屬性,像這樣的例子:

<wpg:PropertyGrid Width="550" Height="550" Instance="{Binding ElementName=button}" /> 
<Button x:Name="button" Content="Click" /> 
+1

是的我的朋友我已經閱讀過它,但它沒有幫助。問題是,當我把控件放在我的窗體中看來控件不可見! 謝謝 – Asha 2009-11-02 13:23:07

16

我知道這是一箇舊的帖子,但在塊上有一個新的PropertyGrid,它是功能最多,功能最豐富的一個。哦,它是免費的!

http://wpftoolkit.codeplex.com/

enter image description here

+0

及時發佈。非常感謝你。 – 2011-11-09 21:21:25