Artur Belico

Hi

I use this code to get a collectionview:

this.view = (CollectionView)CollectionViewSource.GetDefaultView(this.MainPanel.DataContext);

then when I call:
if (this.view.Count == this.view.CurrentPosition + 1)

i get that this.view is null. I just assign the value to the variable at the beginning (loaded event). It works fine the first time, but then it gets null.

Can anyone help me

Thank you,
Artur Carvalho


Re: Windows Presentation Foundation (WPF) collectionview from getdefaultview turns null

Marlon Grech

what is the object inside the mainPanel.DataContext and how is it populated






Re: Windows Presentation Foundation (WPF) collectionview from getdefaultview turns null

Artur Belico

Thanks for the reply.

The object is a XmlDataProvider

I think I narrowed down the problem to this:

If I use this approach it works fine:
XAML:
<XmlDataProvider x:Key="Rss" Source="http://www.publico.clix.pt/rss.asp idCanal=10" XPath="rss/channel/item"/>


If I use this approach the view is null.
XAML:
<XmlDataProvider x:Key="Rss" XPath="rss/channel/item"/>

Code:
XmlDataProvider xdp = this.FindResource("Rss") as XmlDataProvider;
xdp.Source = new Uri("http://www.publico.clix.pt/rss.asp idCanal=10");

It seems that I cannot change the source at runtime.

Can you see the problem

Artur Carvalho






Re: Windows Presentation Foundation (WPF) collectionview from getdefaultview turns null

Marlon Grech

the problem is that the XAML will execute before the code which would cause the binding to break....

this approach is the how I think you should do it

<XmlDataProvider x:Key="Rss" Source="http://www.publico.clix.pt/rss.asp idCanal=10" XPath="rss/channel/item"/>

Good job!

Regards






Re: Windows Presentation Foundation (WPF) collectionview from getdefaultview turns null

Artur Belico

But what I want is to change the source dinamically. I tried to do the binding programatically, but that drove me to the error of the original post.

How would you solve this problem

Thank you ,
Artur Carvalho





Re: Windows Presentation Foundation (WPF) collectionview from getdefaultview turns null

Marlon Grech

have a look at this code sample it should help you....

http://martinparry.com/cs/files/3/wpf/entry14.aspx

basically the guy here is doing what you need updating the source ...

hope it helps....

Regards