单击C#WPF更改资源

时间:2013-05-02 18:24:58

标签: c# wpf binding resources

我的XAML在这里:

<Window.Resources>
    <XmlDataProvider x:Key="rssSource" XPath="//item" Source="https://news.google.com/news?output=rss" />
</Window.Resources>

我需要在按钮点击事件时更改它:

<Window.Resources>
    <XmlDataProvider x:Key="rssSource" XPath="//item" Source="CHANGE WITH TEXTBOX VALUE" />
</Window.Resources>

我该怎么做?

2 个答案:

答案 0 :(得分:1)

在按钮点击事件中放置以下行:

((XmlDataProvider)Resources["rssSource"]).Source = new Uri("<New Source>");

答案 1 :(得分:0)

像这样可能

       XmlDataProvider provider = (XmlDataProvider) this.FindResource("rssSource");
       provider.Source = new Uri("CHANGE WITH TEXTBOX VALUE");