wpf - 在wpf中如何访问用户控件中的window.resources

标签 wpf user-controls resources collectionviewsource

我有一个子用户控件,但无法访问其父用户控件的资源。资源是一个collectionViewSource,它的source设置在parent usercontrol的code behind中,source设置为LINQ to SQL的查询结果。两个用户控件都在它们自己的 xaml 文件中定义。我尝试使用 DynamicResource,它提示说它需要与 DepenednecyProperty 一起使用...

父级用户控制:

...
<UserControl.Resources>
    <CollectionViewSource x:Key="UsageTypeSource"/>
</UserControl.Resources>
...

child 用户控制:

...
<ComboBox Height="28" HorizontalAlignment="Left" Margin="147,1,0,0" x:Name="cbxUsage"
          Grid.Column="1" Grid.Row="2" Width="186"
          SelectedItem="{Binding Path=UsageType, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
          VerticalAlignment="Top" SelectedValuePath="ID"
          SelectedValue="{Binding Path=Usage}"
          ItemsSource="{Binding Source={StaticResource UsageTypeSource}}"
          DisplayMemberPath="Type"/>
...

我收到的错误是“无法解析资源“UsageTypeSource””

你能提供访问资源的正确方法吗

提前致谢 灰

最佳答案

试试这个:

ItemsSource="{DynamicResource UsageTypeSource}}"/> 

关于wpf - 在wpf中如何访问用户控件中的window.resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15419646/

相关文章:

asp.net - 获取 .NET 中特定 div 内的控件列表

c# - 如何执行作为资源嵌入的可执行文件

android - 使用 Ant 构建的 Android 项目中的库资源

c# - 如何从应用程序中启动一个新的应用程序实例?

C#表面设备和压力输入

c# - ICommand 依赖属性

ruby-on-rails - 如何在 Rails 的 map.resources() 中重命名默认标识符参数 "id"?

c# - MVVM 中的后台线程进度通知?

c# - 在 WPF RichTextBox 中将特定文本设置为粗体

c# - 用户控件中具有 CompositeCollection 的 WPF ComboBox 不起作用 : SelectedIndex set to -1