Hi,
Apologies for the change of title - I don't have access to the original emails.
Thanks to the people
who have replied so far.
I am still having problems with trying to access page resources from a user
control.
If I put this withing the control:
<UserControl.Resources>
<vm:PriceViewModel x:Key="PriceViewModel" d:IsDataSource="True" />
</UserControl.Resources>
where vm aliases the namespace:
xmlns:vm="clr-namespace:MyCustomer.MyProject.ViewModel"
Then I can access the ViewModel object, however it's a newly instantiated
instance of that view
model object.
My preference is to reuse the existing one that exists on the parent Page, as
that one already has
data loaded that I want to use, hence less unnecessary database requests.
fyi, the price view model object is declared in the xaml as:
<navigation:Page.Resources>
<vm:PriceViewModel x:Key="PriceViewModel" d:IsDataSource="True" />
</navigation:Page.Resources>
This exists in the constructor of the page (after InitializeComponent), and, as
expected, is not null.
So the following line
moPriceViewModel = Resources["PriceViewModel"] as PriceViewModel;
is set correctly.
Adding the DataContext did nothing. I added it in the xaml in both the page and
in the control root
element, then I tried adding the view model object in the code behind on the
parent page, but it
still came through null.
The datatype of the Parent property is DependencyObject, and it is null when I
attempt to access it
from within the constructor of the control (after the InitializeComponent
statement), even though
the control exists in the xaml of the parent. Help suggests that I need to set
the Parent property by
adding the control to a collection. I did that explicitly (although I believe
it should already be set
within the xaml), adding it to the layout grid, but Parent still came through
null.
I also tried
ManageTermsPage mtp = (ManageTermsPage)VisualTreeHelper.GetParent(this);
but I think this failed for the same reason - Parent property is null.
If I could get the DataContext working, passing the datasource through from the
page to the
control, I would be happy with that.
I do need access to the resource from within the xaml and in the code-behind.
Any other ideas on how I might achieve this?
Regards,
Tony
_______________________________________________
ozsilverlight mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight