Silverlight Toolkit 主题:使用 TreeView 设置主题时出现异常
我在尝试以编程方式应用 Silverlight Toolkit 主题时遇到了问题。在某些情况下,设置主题时会引发例外情况。
XAML:
<StackPanel>
<Button HorizontalAlignment="Left"
Content="Press To Set Theme"
Click="Button_Click" />
<sdk:TreeView>
<sdk:TreeViewItem Header="Items">
<TextBlock Text="Item" />
</sdk:TreeViewItem>
</sdk:TreeView>
</StackPanel>
代码隐藏:
private void Button_Click(object sender, RoutedEventArgs e)
{
TwilightBlueTheme.SetIsApplicationTheme(Application.Current, true);
}
如果我启动它,然后展开 TreeView,然后单击按钮,我会得到以下信息:
System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
编辑:
我现在尝试了一种不同的方法来执行此操作,但它仍然会因相同的错误而中断。我将 xaml 包装在主题中,如下所示:
<toolkit:Theme x:Name="ThemeContainer"
ThemeUri="/System.Windows.Controls.Theming.TwilightBlue;component/Theme.xaml">
...
</toolkit:Theme>
然后将主题切换更改为:
Theme themeContainer = (Theme)((FrameworkElement)Application.Current.RootVisual).FindName("ThemeContainer");
themeContainer.ThemeUri = new Uri("/System.Windows.Controls.Theming.ExpressionDark;component/Theme.xaml"), UriKind.RelativeOrAbsolute);
相同情况:它可以工作,除非我已经扩展了 TreeView 那么它会因相同的错误而中断。
2010 年 4 月推出的 SL4
I've run into a problem trying to programmatically apply a Silverlight Toolkit Theme. An exception is raised upon setting the theme, under certain conditions.
XAML:
<StackPanel>
<Button HorizontalAlignment="Left"
Content="Press To Set Theme"
Click="Button_Click" />
<sdk:TreeView>
<sdk:TreeViewItem Header="Items">
<TextBlock Text="Item" />
</sdk:TreeViewItem>
</sdk:TreeView>
</StackPanel>
Code Behind:
private void Button_Click(object sender, RoutedEventArgs e)
{
TwilightBlueTheme.SetIsApplicationTheme(Application.Current, true);
}
If I start it, then expand the TreeView, and then click the button, I get this:
System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
EDIT:
I've now tried a different way of doing this, and it still breaks with the same error. I wrapped the xaml in a Theme, like so:
<toolkit:Theme x:Name="ThemeContainer"
ThemeUri="/System.Windows.Controls.Theming.TwilightBlue;component/Theme.xaml">
...
</toolkit:Theme>
And then changed the theme-switching to:
Theme themeContainer = (Theme)((FrameworkElement)Application.Current.RootVisual).FindName("ThemeContainer");
themeContainer.ThemeUri = new Uri("/System.Windows.Controls.Theming.ExpressionDark;component/Theme.xaml"), UriKind.RelativeOrAbsolute);
Same situation: it works, except if I've already expanded the TreeView then it breaks with the same error.
SL4 w/ April 2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,看来这是 SL 工具包中的一个错误。如果在树展开时设置主题,我会收到此错误:
无论如何,使用主题的常用方法是完美的:
这是主题命名空间定义:
Well, it's seems that this is a bug from SL toolkit. I get this error if set the theme when the tree is expanded:
Anyway, the usual way of using themes works flawless:
This is the theme namespace definition:
看看 这篇文章介绍如何使用 Silverlight Toolkit 动态更改主题
Look at this post about how dynamically change the theme with Silverlight Toolkit