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 3495626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:08:58+00:00 2026-05-18T12:08:58+00:00

I defined the following resources: <DataTemplate x:Key=DragTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height=40></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition

  • 0

I defined the following resources:

    <DataTemplate x:Key="DragTemplate">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="40"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <Label x:Name="DraggingSourceLabel" Content="{Binding Name}" BorderThickness="2" BorderBrush="White" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Grid.Row="0" Grid.Column="0" FontSize="20"></Label>
        </Grid>
    </DataTemplate>

    <Style x:Key="CursorStyle" TargetType="{x:Type ContentControl}">
        <Setter Property="Opacity" Value="0.50"/>
        <Setter Property="Background" Value"Black"/>
        <Setter Property="ContentTemplate" Value="{StaticResource DragTemplate}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <ContentPresenter 
                        Content="{TemplateBinding Content}" 
                        ContentTemplate="{TemplateBinding ContentTemplate}">
                    </ContentPresenter>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Tag"  Value="DragEnter">
                <Setter Property="Opacity" Value="1.0"/>
                <Setter Property="Background" Value="Red"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</s:SurfaceWindow.Resources>

But unfortunately, the StyleTriggers aren’t working how I thought. The Opacity is changed, but the Background is still the same. I also tried it with only one setter, but the background still didn’t changed:

<Style.Triggers>
                <Trigger Property="Tag"  Value="DragEnter">

                    <Setter Property="Background" Value="Red"/>
                </Trigger>
            </Style.Triggers>

What’s the problem here?

===EDIT===

Here the code I use to get the ContentControl:

ContentControl cursorVisual = new ContentControl()
                {
                    Content = data,
                    Style = window.FindResource("CursorStyle") as Style

                };

                List<InputDevice> devices = new List<InputDevice>();
                devices.Add(e.Contact);


                ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

                bool startDragOkay = SurfaceDragDrop.BeginDragDrop(sender as Grid, draggedElement, cursorVisual, data, devices, DragDropEffects.Move);      

                if (startDragOkay)
                {
                    e.Handled = true;
                    //draggedElement.Visibility = Visibility.Hidden;
                }
  • 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-18T12:08:59+00:00Added an answer on May 18, 2026 at 12:08 pm

    Style can’t set Background because this property, unlike Opacity, isn’t exist in a FrameworkElement class. Properties of a Framework element may be used out of the box, but properties of a Control (such as Background, BorderThickness, HorizontalContentAlignment) should be defined inside a template.

    Here is a correct version, I’ve added a border with background:

    <ControlTemplate TargetType="{x:Type ContentControl}">
        <Border Background="{TemplateBinding Background}">
            <ContentPresenter
                Content="{TemplateBinding Content}" 
                ContentTemplate="{TemplateBinding ContentTemplate}">
            </ContentPresenter>
        </Border>
    </ControlTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following AutoCompleteBox defined inside DataTemplate: <Window.Resources> <DataTemplate x:key=PaneTitleTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition
I defined a DataTemplate the following way: <s:SurfaceWindow.Resources> <ImageBrush x:Key=WindowBackground Stretch=None Opacity=0.6 ImageSource=pack://application:,,,/Resources/WindowBackground.jpg/> <DataTemplate
I have the following treeview defined in my xaml: <TreeView Name=PST_TreeView Grid.Row=0 Grid.Column=0 Width=Auto
Within my Windows.Resources I have the following column defined: <DataGridTextColumn x:Key=CustomColumn x:Shared=False> <DataGridTextColumn.Header> <StackPanel>
In <Window.Resources> I have defined following style: <Style x:Key=textBlockStyle TargetType=TextBlock> <Setter Property=Margin Value=5,0,5,0/> </Style>
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
I have the following xaml code in resources: <DataTemplate DataType={x:Type s:Substance}> <StackPanel Orientation=Horizontal> <TextBlock
Having the following very simple xaml: <DocumentViewer Name=dv> <FixedDocument Name=fd Loaded=fd_loaded> <FixedDocument.Resources> <Style x:Key=TestStyle>
I have the following routes defined: resources :patients do collection do get 'import' =>

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.