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

  • Home
  • SEARCH
  • 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 3394984
In Process

The Archive Base Latest Questions

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

So, I have this Window with some controls. In the resources section I’ve defined

  • 0

So, I have this Window with some controls. In the resources section I’ve defined this style:

<Style x:Key="StyleNavBar" TargetType="{x:Type Grid}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding CurrentTheme, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
            <DataTrigger.Value>
                <theme:WinTheme>WindowsClassic</theme:WinTheme>
            </DataTrigger.Value>
            <Setter Property="Background" Value="#FFFFFFFF" />
        </DataTrigger>
    </Style.Triggers>
</Style>

In my Window I define an attached property named ‘CurrentTheme’ which stores (based on an enum) the current theme used system-wide. Here’s the code:

public static readonly DependencyProperty CurrentSystemThemeProperty =
    DependencyProperty.RegisterAttached(
        "CurrentSystemTheme",
        typeof(WinTheme),
        typeof(MainWindow),
        new UIPropertyMetadata(WinTheme.AeroGlass));

public WinTheme CurrentTheme
{
    get
    {
        return (WinTheme)GetValue(CurrentSystemThemeProperty);
    }
    set
    {
        SetValue(CurrentSystemThemeProperty, value);
    }
}

Everytime the user changes the system theme, my window receives a callback via WndProc, informing that the theme has changed. And, as you can see, the default value of the CurrentTheme property is WinTheme.AeroGlass. Then I have a grid styled with the style defined above:

<Grid Height="34" Name="grdNavBar" VerticalAlignment="Top" Style="{DynamicResource StyleNavBar}">

My goal is to change the style based on the value of CurrentTheme, but the trigger defined above does not work when the theme changes (it only works with the default value of CurrentTheme, i.e., isn’t reacting to changes in the property).

Any ideas on how to accomplish this?

  • 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-18T04:14:09+00:00Added an answer on May 18, 2026 at 4:14 am

    You’ve passed a different name to DependencyProperty.RegisterAttached than the name you’ve given the property in C#. So the DP system thinks it’s called CurrentSystemTheme, but your code thinks it’s called CurrentTheme. Try passing CurrentTheme as the first argument to RegisterAttached.

    Also, you might want to enable WPF debug log output for data binding (which is on by default in older versions of WPF, but in .NET 4/VS 2010, you need to go and switch it on in the Tools->Options window under Debugging->Output Window). That way, I usually set the WPF Trace Settings -> Data Binding option to All. That way if a data binding fails, you’ll see an error in the Output window. This might help you diagnose why that data trigger is failing.

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

Sidebar

Related Questions

Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key=whatever Text=foo\nbar /> </Window.Resources> Obviously
I have a window in WPF which shows some media contents. This content contains
I have added some code which compiles cleanly and have just received this Windows
This is a Windows Forms application. I have a function which captures some mouse
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I have this function in my head: <head> window.onload = function(){ var x =
I have asp.net form that contains fields. When I access this window, my javascript
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
More particularly - I have a window handle of another running application. This application
I have a greasemonkey user script with this single line of code... window.close(); but

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.