I have two styles in two resource dictionaries. When application load then I have loaded one (`Dictionary1.xaml`) resource. After that when I click on button then I want to change style. i.e I want to load `Dictionary2.xaml`. I have changed but there is no effect on my button.
Dictionary1.xaml
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Dictionary2.xaml
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
When application load then
Uri sUri = new Uri("/KeyCheck;component/Dictionary1.xaml", UriKind.Relative);
ResourceDictionary r = new ResourceDictionary();
r.Source = sUri;
Resources.MergedDictionaries.Add(r);
Apply style in page: Main.xaml
When click on button then:
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri sUri = new Uri("/KeyCheck;component/Dictionary1.xaml", UriKind.Relative);
ResourceDictionary r = new ResourceDictionary();
r.Source = sUri;
App.Current.Resources.MergedDictionaries.Remove(r);
sUri = new Uri("/KeyCheck;component/Dictionary2.xaml", UriKind.Relative);
r = new ResourceDictionary();
r.Source = sUri;
App.Current.Resources.MergedDictionaries.Add(r);
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Marutharasu P50 reputationPosted Jan 29, 2014, 10:56 PM EST
Ex:
// Doesn't Work
// Does Work