我搜索并尝试了许多操作来完成此操作。我有一个成功做XAML代码像这样绑定到多个XAML框架风格,样式的名称是ViewPersonTextboxDataStyle:如何从后面代码中的Common/StandardStyles.xaml中指定XAML Stype
<TextBox Grid.Row="5" Grid.Column="1" Name="textboxName" Text="{Binding textboxName}" Margin="5,5,5,5" Style="{StaticResource ViewPersonTextboxDataStyle}"/>
所以,当我到达另一个框架,我想创建网格行并在代码定义的背后,我想这一点,我认为是正确的:
var resourceDictionary = new ResourceDictionary()
{
Source = new Uri("ms-appx:///Common/StandardStyles.xaml", UriKind.Absolute)
};
var style = resourceDictionary["ViewPersonTextboxDataStyle"] as Style;
textBlock.Style = resourceDictionary["ViewPersonTextboxDataStyle"] as Style;
所以在这一点上,我可以看到在资源字典中发现的样式正确填充样式。但是分配到textBlock.Style会导致一个灾难性异常(Catastrophic Exception)。所以,要么我错过了一个步骤,要么这是不正确的。
没有很多关于这方面的净信息。
这仍然给[System.Runtime.InteropServices.COMException] = {“错误HRESULT E_FAIL已从调用COM组件返回。”} – RallyRabbit
实际上,这是因为this.Resources没有密钥。 – RallyRabbit
@RallyRabbit:我编辑了我的答案。请检查 – Raghavendra