【问题标题】:How to bind to a resource in another project's properties in WPF?如何在 WPF 中绑定到另一个项目属性中的资源?
【发布时间】:2014-05-29 01:45:51
【问题描述】:

我正在尝试将 xaml 中的列表绑定为 itemsource。问题是,该列表保存在另一个项目属性中的资源文件中(在同一解决方案中)。我一直在尝试创建一个命名空间,但它继续告诉我 myproject.Properties.Resources 显然不存在。

帮助解释粗略想法的简短示例: 项目1.xaml

<Grid ItemsSource={Binding (binding goes here)} />

Project2.Properties.Resources

public static namespace.listobject MyList;

希望它相对简单,有人可以尽快给我答案。提前致谢!

【问题讨论】:

  • 你搜索过这个吗? this question 适合你吗?
  • 我搜索了一下。我以前没看到,但还是不行。
  • 你有同样的错误吗? (出于好奇,您是否尝试重建您的解决方案?)
  • 是的,同样的错误。我已经多次清理并重建了解决方案。这是项目的属性;它们永远存在。
  • 我可以把它放到项目中,但它不想在项目中找到属性。

标签: wpf xaml binding


【解决方案1】:

如果您在 SolutionExplorer -> Properties -> Resspource -> AddRessource 上定义了资源,那么实施此解决方案应该没有问题:

<Window>
    <Window.Resources>
            <BitmapImage x:Key="Image1" UriSource="Resources/yourimage.bmp" />
    </Window.Resources>
   <Grid>
       <Image  Source="{StaticResource Image1}"/>
   </Grid>
</Window>

不要忘记将图像文件的Build Action 属性设置为Ressource

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多