例XAML类型动态加载XAML被加载动态使用具有代码隐藏
<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:usercontrols='clr-namespace:App.Views.UserControls'>
<TextBlock>Why don't you click the button?</TextBlock>
<usercontrols:SuperButton
Command="{Binding DataContext.OpenURLNew,RelativeSource=
{RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}"
CommandParameter="50">
ClickMe</usercontrols:SuperButton>
</Grid>
加载这个失败,“无法加载未知类型用户控件:superbutton”,尽管SuperButton中定义的事实相同的组件。
我猜这是因为SuperButton有关联的代码隐藏?有没有办法帮助XamlReader.Load()找到它所需要的?
这奏效了!谢谢一堆。 Upvoted和接受。一旦我有机会,将看看你的netgooey的东西。一段解释你已经建立/尝试实现的内容将很方便。从我所看到的,你必须挖掘代码才能找出目前的情况。 – 2012-07-09 20:02:21
是的。我不再支持这个项目,所以我不会写文档。我提到它主要是因为可能有一些例子说明你应该如何在那里做事。如果您有其他WPF /动态XAML问题,您可以通过指向新问题的链接回复此评论,我会看一看。 – 2012-07-09 20:05:34