Live Chat Icon For mobile
Live Chat Icon

How can I define a style for a ContentControl to give it a meaningful appearance in the UI ?

Platform: WPF| Category: Templates

This can be done as follows.

[XAML]

<Style x:Key='ContentCtrl' TargetType='ContentControl'>
    <Setter Property='Background' Value='Red'/>
    <Setter Property='Foreground' Value='Green'/>
    <Setter Property='FontSize' Value='20'/>
    <Setter Property='FontWeight' Value='Bold'/>
    <Setter Property='Template'>
        <Setter.Value>
            <ControlTemplate TargetType='ContentControl'>
                <Grid>
                    <Ellipse Width='{TemplateBinding Width}' Height='{TemplateBinding Width}' Fill='{TemplateBinding Background}'/>
                    <ContentPresenter VerticalAlignment='Center' HorizontalAlignment='Center'/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

...

<ContentControl Width='75' Height='100' Style='{StaticResource ContentCtrl}' Content='Hello'/>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.