《silverlight引用皮肤经常出现的问题.doc》由会员分享,可在线阅读,更多相关《silverlight引用皮肤经常出现的问题.doc(7页珍藏版)》请在金锄头文库上搜索。
1、这个问题相信很多人遇见,我也遇见过。所以我找到了解决的方法先看一个效果:这是引用sl4的toolkit皮肤的默认效果这是引用了Bureaublue的效果:这是引用了ExpressionDark的效果:我们看一下前台代码: 我们看见ComboBox有个SelectionChanged事件,事件的代码如下:private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e) if (comboBox2.SelectedValue.ToString()!=) ComboBoxItem item = co
2、mboBox2.SelectedValue as ComboBoxItem; SwitchTheme(item.Content.ToString(); /切换皮肤的方法 void SwitchTheme(string themeName) ResourceDictionary rd = new ResourceDictionary(); rd.Source = new Uri( string.Format( /SwitchThemes;component/Assets/0Theme.xaml ,themeName ), UriKind.Relative); Application.Curren
3、t.Resources.MergedDictionaries.Add(rd); 我们再看一段代码: void SwitchTheme(string themeName) ResourceDictionary rd = new ResourceDictionary(); rd.Source = new Uri( string.Format( Assets/0Theme.xaml ,themeName ), UriKind.Relative); Application.Current.Resources.MergedDictionaries.Add(rd); 感觉这段代码没有错误,但是这时候却报异
4、常如下图:为什么呢?我也不明白,我只知道这是silverlight的路径的一种引用方式吧,如果我们把代码稍微一改就不会出错了,改成这样:void SwitchTheme(string themeName) ResourceDictionary rd = new ResourceDictionary(); rd.Source = new Uri( string.Format( /SwitchThemes;component/Assets/0Theme.xaml ,themeName ), UriKind.Relative); Application.Current.Resources.MergedDictionaries.Add(rd); 这时候问题就解决了2.但是很多人不是因为这个问题,而是因为ComboBox的问题,出现上面的异常前台代码: comboBox2_SelectionChanged代码:private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e) if (comb