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 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Marutharasu PPosted Jan 30, 2014, 3:56 AM
Ex:
// Doesn't Work
// Does Work