【问题标题】:How to define a static wpf ressource from c# project settings (properties) defined in another project如何从另一个项目中定义的 c# 项目设置(属性)定义静态 wpf 资源
【发布时间】:2017-01-02 21:26:53
【问题描述】:

位于 App.xaml 中的以下代码定义了一个静态应用程序范围的资源,我成功地将其绑定到一个列表框控件。

<Application x:Class="cviko.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:properties="clr-namespace:cviko.Properties"
         StartupUri="MainWindow.xaml">
    <Application.Resources>
        <CollectionViewSource x:Key="SStrings"
             Source="{Binding Source={x:Static properties:Settings.Default}, Path=Strings}">
        </CollectionViewSource>
    </Application.Resources>

然而,我想做同样的事情,而是使用另一个项目中定义的属性。像这样的东西(不可编译):

<Application x:Class="cviko.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:properties="clr-namespace:cviko.Properties"
         //NEW
         xmlns:props="clr-namespace:UIComponents.Properties" 
         StartupUri="MainWindow.xaml">
    <Application.Resources>
        //MODIFIED
        <CollectionViewSource x:Key="SStrings"
             Source="{Binding Source={x:Static props:Settings.Default}, Path=Nums}">
        </CollectionViewSource>
</Application.Resources>

欢迎任何建议,谢谢。

【问题讨论】:

    标签: c# wpf application-settings assembly-references static-resource


    【解决方案1】:

    天哪,我发帖后马上就明白了:

    1) 我需要使用这个:

    xmlns:props="clr-namespace:UIComponents.Properties;assembly=UIComponents"
    

    2) 最重要的是:必须将设置设置为公开,但我忽略了这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多