Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4336792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:51:21+00:00 2026-05-21T10:51:21+00:00

How can I apply a style to the content of a contentcontrol. For example:

  • 0

How can I apply a style to the content of a contentcontrol. For example:

<Window.Resources>
    <Controls:DataGrid x:Key="PersonDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding .}" x:Shared="False">
        <Controls:DataGrid.Columns>
            <Controls:DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}" IsReadOnly="True"/>
            <Controls:DataGridTextColumn Header="Last Name" Binding="{Binding Path=LastName}" IsReadOnly="True"/>
        </Controls:DataGrid.Columns>
    </Controls:DataGrid>
</Window.Resources>

<StackPanel>
    <ContentControl Content="{StaticResource PersonDataGrid}" DataContext="{Binding Path=Customers}" Style="DataGridStyle1"></ContentControl>
    <ContentControl Content="{StaticResource PersonDataGrid}" DataContext="{Binding Path=Employees}" Style="DataGridStyle2"></ContentControl>
</StackPanel>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:51:21+00:00Added an answer on May 21, 2026 at 10:51 am

    EDIT 2: It looks like you’re trying to apply a different Style to each of your DataGrids. To do this, you’re going to need to define their specific Style inside the Resources Section of each ContentControl. If the styles are defined elsewhere, you can always create a new style based on the style defined elsewhere as shown below

    The first ContentControl’s DockPanel’s Background will be Black. The second’s will be Blue.

    <Window.Resources>
        <Style TargetType="DockPanel" x:Key="DockStyle1">
            <Setter Property="Background" Value="Black" />
        </Style>
        <Style TargetType="DockPanel" x:Key="DockStyle2">
            <Setter Property="Background" Value="Blue" />
        </Style>
        <DockPanel x:Key="MyDockPanel">
            <Rectangle Fill="Green" DockPanel.Dock="Top" Height="20" Width="50" />
            <Rectangle Fill="Red" DockPanel.Dock="Top" Height="20" Width="20" />
            <Rectangle Fill="Yellow" DockPanel.Dock="Bottom" Height="20" Width="50" />
        </DockPanel>
    </Window.Resources>
    <StackPanel>
        <StackPanel>
            <ContentControl Content="{StaticResource MyDockPanel}">
                <ContentControl.Resources>
                    <Style TargetType="{x:Type DockPanel}" BasedOn="{StaticResource DockStyle1}" />
                </ContentControl.Resources>
            </ContentControl>
            <ContentControl Content="{StaticResource MyDockPanel}">
                <ContentControl.Resources>
                    <Style TargetType="DockPanel" BasedOn="{StaticResource DockStyle2}" />
                </ContentControl.Resources>
            </ContentControl>
        </StackPanel>
    </StackPanel>
    

    EDIT 3 – For your example, I think you want something like this (I can’t test this however as I don’t have access to your ‘Controls’ namespace):

    <Window.Resources>
        <Controls:DataGrid x:Key="PersonDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding .}" x:Shared="False">
            <Controls:DataGrid.Columns>
                <Controls:DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}" IsReadOnly="True"/>
                <Controls:DataGridTextColumn Header="Last Name" Binding="{Binding Path=LastName}" IsReadOnly="True"/>
            </Controls:DataGrid.Columns>
        </Controls:DataGrid>
    </Window.Resources>
    
    <StackPanel>
        <ContentControl Content="{StaticResource PersonDataGrid}" DataContext="{Binding Path=Customers}">
            <ContentControl.Resources>
                <Style TargetType="{x:Type Controls:DataGrid}" BasedOn="{StaticResource DataGridStyle1}" />
            </ContentControl.Resources>
        </ContentControl>
        <ContentControl Content="{StaticResource PersonDataGrid}" DataContext="{Binding Path=Employees}">
            <ContentControl.Resources>
                <Style TargetType="{x:Type Controls:DataGrid}" BasedOn="{StaticResource DataGridStyle2}" />
            </ContentControl.Resources>
        </ContentControl>
    </StackPanel>
    

    Unfortunately, you cannot Style DataGridTextColumns as stated in Why can't I style a DataGridTextColumn?

    Instead, I generally set the CellStyle of a DataGridTextColumn to ‘style’ it:

    <Style TargetType="DataGridCell" x:Key="DataGridCenteredText">
        <Setter Property="TextBlock.TextAlignment" Value="Center" />
    </Style>
    
    <DataGridTextColumn Header="Centered Text" CellStyle="{StaticResource DataGridCenteredText}" Binding="{Binding Path=MyData}" />
    

    I think you’ll need to define the CellStyle on a per column basis however (I can’t think of any reason why you wouldn’t anyway.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i apply style like this, $('#aspnetForm').append($('#facebox .content').html().css({ 'display': 'none' })); but it didnt
I know that you can apply CSS in order to style objects in Flex
Normally when we are using Master/Content style pages, we apply the css to Master
I need to apply a custom style to my datepicker but can't work out
Looking at tooltip support in Flex, I've seen you can apply colors and styles
I understand I can apply several options to the ServiceContract (like Name , Namespace
if i have a function A,which can apply a certain rule on a given
When using Visual Studio (though ideally this can apply to the generic case) and
Is there a way I can apply '+ to '( 1 2 3)? edit:
here i need a batch file which can apply and create label or base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.