簡體   English   中英

wpf propertyGrid

[英]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>

代碼背后:

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

請幫助我找出為什么它不可見

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

http://wpftoolkit.codeplex.com/

在此輸入圖像描述

這是由於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>

或者如果您願意,可以將其放在窗口中的標簽中。

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

祝你有美好的一天!

對於任何有興趣的人,我已經開始了一個簡單的 - 但我希望有用的 - 用於WPF的免費和開源的PropertyGrid項目。

源代碼可在此處獲得: https//github.com/SoftFluent/SoftFluent.Windows ,此處還有一個nuget包: https ://www.nuget.org/packages/SoftFluent.Windows。

它沒有依賴關系,但需要.NET 4,因為它使用WPF的.NET 4 DataGrid類

您是否在下載頁面閱讀了文檔?

WPF屬性網格下載頁面

您似乎必須引用要編輯的屬性,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM