C# WPF Change Resource On Click
My XAML is here:
<Window.Resources> <XmlDataProvider x:Key="rssSource" XPath="//item" Source="https://news.google.com/news?output=rss" /> </Window.Resources>
I need to change it when button click event:
<Window.Resources> <XmlDataProvider x:Key="rssSource" XPath="//item" Source="CHANGE WITH TEXTBOX VALUE" /> </Window.Resources>
How can i do it?
Answers
Like this maybe
XmlDataProvider provider = (XmlDataProvider) this.FindResource("rssSource"); provider.Source = new Uri("CHANGE WITH TEXTBOX VALUE");
Inside the button click event put this line:
((XmlDataProvider)Resources["rssSource"]).Source = new Uri("<New Source>");