I try to add a usercontrol in my Windows phone project witch has to display my personnal ads. The control works great with default embeded ads but when i want to add personnal ads from the Windows Phone project, i have 2 different issues.
Method 1 : PROPERTY
public static PersonalAdsCollection Ads
{
get { return myAds; }
set { myAds = value; }
}
Method 2 : DEPENDANCY PROPERTY
public PersonalAdsCollection Ads
{
get { return (PersonalAdsCollection)GetValue(AdCollectionProperty); }
set
{
SetValue(AdCollectionProperty, value);
//this.Dispatcher.BeginInvoke(() => myAds = value);
//myAds = value;
}
}
public static readonly DependencyProperty AdCollectionProperty =
DependencyProperty.Register(
"Ads",
typeof(PersonalAdsCollection),
typeof(AdRotator),
new PropertyMetadata(null, OnAdsSourceChanged)
);
private static void OnAdsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
myAds = (PersonalAdsCollection)e.NewValue;
}
//in the constructor :
//SetValue(AdCollectionProperty, new PersonalAdsCollection());
WINDOWS PHONE PROJECT FOR BOTH
<myAdRotator:AdRotator
VerticalAlignment="Bottom"
>
<myAdRotator:AdRotator.Ads>
<myAdRotator:PersonalAd
LocalImageUrl="/Assets/pub480x80.jpg"
LinkUrl=""
/>
</myAdRotator:AdRotator.Ads>
</myAdRotator:AdRotator>
RESULTS METHOD 1 Visual studio shows the ad in the Windows phone project visual xaml view but the Windows phone project does not compile because it can't find a AdRotator.Ads Property
RESULT METHOD 2 Visual studio shows nothing but the app runs and display the ad embeded in the usercontrol, not the one set on the Windows phone project. The AdRotator.Ads setter and OnAdsSourceChanged are never called.
MY SEARCH I found the subjects : - Bound Property Setter not getting Called - WPF UserControl Dependency Property Setter not triggering
I can't figure how to make it works.
Thank you for your help.
EDIT: With the modified code, it compiles and calls OnAdsSourceChanged after the constructor's SetValue... But it does not care about the Xaml defined in the Windows phone app project :(