在App.xaml文件中创建资源时遇到问题。我的问题是,我想实例化一个在构造函数中需要参数的对象(在这种情况下是Linq到Sql DataContext),但我不知道是否可以在XAML中传递这样的参数。有人知道解决这个问题的方法吗?我想在XAML中全局访问此数据上下文,我的想法是可以将其作为参数传递给Contoso:
<ObjectDataProvider x:Key="PriceCodeProvider" x:Name="priceCodeProvider" ObjectType="{x:Type local:PriceCodeObjectDataProvider}" >
<ObjectDataProvider.ConstructorParameters>
<StaticResource ResourceKey="MyDataContext" />
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
从设计的角度来看,我相信有更好的方法来实现我想要的东西,但我对WPF还是相当陌生的。..在一点帮助下,我认为这将完成我的特定项目。
谢谢!
-查尔斯