Skip to main content
Microsoft Silverlight
Home Forums General Silverlight Programming Silverlight Controls and Silverlight Toolkit Custom Content Property
3 replies. Latest Post by laurencl on June 18, 2009.
(0)
dydydy
Member
7 points
27 Posts
05-08-2009 4:44 PM |
Hi, I have a question,
I have a WS.xaml file, with its code behind, and it will be compiled to a binary dll file
<UserControl x:Class="WS.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="100"> <Grid x:Name="LayoutRoot" Background="Black" Visibility="Collapsed"> <MediaElement x:Name="StreamVideo" Source=""> </MediaElement> </Grid></UserControl>
In my client side, I would like to include this dll with another xaml using
xmlns:n="clr-namespace:WS;assembly=WS"
and <n:MainPage x:Name="WSPage" />
but how do create a content property so that when I type <n:MainPage x:Name="WSPage" VideoUrl="http://www.xxxxx.com/xx.wmv" />
so VideoUrl will change the MediaElement in the WS.xaml's source ?
SharpGIS
Contributor
4359 points
755 Posts
05-08-2009 4:51 PM |
Create a property on your MainPage class:
public Uri VideoSource { get; set; }
Then on the loaded event of the control, set the video source :
StreamVideo.Source = this.VideoSource;
If you want to be able to change it on the fly (after the page has loaded), you can do this in the setter of your property too.
You could take this even further and start getting into control templates, template binding, dependency properties etc, but for something this simple that is probably overkill.
05-08-2009 5:20 PM |
Hi, Thanks for answering
With your solution, I still can't achieve the goal where I can set <n:MainPage x:Name="WSPage" VideoSource="" />
What is the best way to achieve this custom property goal?
laurencl
10 points
5 Posts
06-18-2009 12:25 PM |
Your MainPage class must, of course, implement the VideoSource property, but must also override ToString(). ToString is what is used in {StaticResource xxx} in the xaml.