XmlDataProvider Refresh WPF Source

I have a WPF grid

<Window x:Class="LabsRSS.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Poperecinii Timur Lab" Height="404" Width="588">
<Grid x:Name="blah">
    <Grid.Resources>
        <XmlDataProvider x:Key="flickrdata" Source="http://api.flickr.com/services/feeds/photos_public.gne?tags=dog&amp;lang=en-us&amp;format=rss_200">
            <XmlDataProvider.XmlNamespaceManager>
                <XmlNamespaceMappingCollection>
                    <XmlNamespaceMapping Prefix="media" Uri="http://search.yahoo.com/mrss/"/>
                </XmlNamespaceMappingCollection>
            </XmlDataProvider.XmlNamespaceManager>
        </XmlDataProvider>
        <DataTemplate x:Key="itemTemplate">
            <Image Width="75" Height="75" Source="{Binding Mode=OneWay, XPath=media:thumbnail/@url}"/>
        </DataTemplate>
        <ControlTemplate x:Key="controlTemplate" TargetType="{x:Type ItemsControl}">
            <WrapPanel IsItemsHost="True" Orientation="Horizontal"/>
        </ControlTemplate>
    </Grid.Resources>
    <ItemsControl
   Width="375"
   ItemsSource="{Binding Mode=Default, Source={StaticResource flickrdata}, XPath=/rss/channel/item}"
   ItemTemplate="{StaticResource itemTemplate}"
   Template="{StaticResource controlTemplate}">
    </ItemsControl>
    <TextBox Height="23" Margin="193,0,213,24" Name="textBox1" VerticalAlignment="Bottom" TextChanged="textBox1_TextChanged" />
</Grid>

      

What I am trying to do is replace the tag with its own input from the TextBox.

 private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
    {
        XmlDataProvider dataProvider = (XmlDataProvider)this.blah.FindResource("flickrdata");
        XmlNamespaceManager xnManager = dataProvider.XmlNamespaceManager;
        string newSource = "http://api.flickr.com/services/feeds/photos_public.gne?tags=flower&amp;lang=en-us&amp;format=rss_200";
        newSource = Regex.Replace(newSource, "(^.*tags=)(.+?)(&amp;.*$)", String.Format("{0}{1}{2}", "$1", textBox1.Text, "$3"));
        dataProvider.Source = new Uri(newSource);
        dataProvider.XmlNamespaceManager = xnManager;
        dataProvider.Refresh();

    }

      

Now the uri seems to be configured well, but the dataProvider is not updating the content, how can I do that?

+2


source to share


1 answer


Actually I don't think you want to call Refresh ... or reinstall XmlNamespaceManger. I think the call to Refresh is actually telling the XmlDataProvider to reload the same source it already had.



When changing the source, that should be all it takes to run the load logic. If you want to re-set the XmlNamespaceManager, you must call DeferRefresh, because otherwise the provider will reload every time the property changes.

0


source







All Articles