简体   繁体   中英

Creating Silverlight Overlay User Control

I'm creating a silverlight user control that will display a transparent overlay with text over whatever xaml is contained if a property is set to true. So for example:

<my:Overlay Message="You don't have access to this feature." ShowOverlay="{Binding IsFeatureAvailable}">

<TextBox />
<Button Content="Search" />

</my:Overlay>

What I'm not quite sure about is how to implement the ability to put arbitrary xaml inside my user control, like above.

Thanks for any help.

Inherit your OverlayControl from ContentControl . Your template would look something like:

<Grid>
    <Grid x:Name="Overlay" Background="#30000000">
        <ContentPresenter Content="{TemplateBinding Content}"/>
    </Grid>
    <TextBlock Text="{TemplateBinding Message}"/>
</Grid>

This should work

<Grid>
<my:Overlay Message="You don't have access to this feature." ShowOverlay="{Binding IsFeatureAvailable}"/>

<TextBox />
<Button Content="Search" />

</Grid>

Also you can derrive you Overly control from ContentControl, and put content and OverLay layer in grid like shown above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM