Skip to main content

MSDN

Answered Question Custom Content PropertyRSS Feed

(0)

dydydy
dydydy

Member

Member

7 points

27 Posts

Custom Content Property

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
SharpGIS

Contributor

Contributor

4359 points

755 Posts

Answered Question

Re: Custom Content Property

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.

--
/Morten | blog - twitter
Please click on "Mark as Answer" if this answered your question.

dydydy
dydydy

Member

Member

7 points

27 Posts

Re: Re: Custom Content Property

 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
laurencl

Member

Member

10 points

5 Posts

Re: Re: Custom Content Property

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.

  • Unanswered Question
  • Answered Question
  • Announcement