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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:40:33+00:00 2026-05-16T01:40:33+00:00

I thought that element property syntax and attribute property syntax have no big semantical

  • 0

I thought that element property syntax and attribute property syntax have no big semantical difference. However, I found that there must be some difference.

E.g. The following example just demonstrates a simple trigger:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button><Button.Template>
  <ControlTemplate TargetType="{x:Type Button}">
    <TextBlock x:Name="hello" Text="Hello" />
    <ControlTemplate.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Foreground" Value="Red" TargetName="hello"/>
     </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
</Button.Template></Button>
</Page>

However, if I used a element property syntax for property Property of trigger, it throws an exception saying that setter! (not trigger) requires both property and value.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button><Button.Template>
  <ControlTemplate TargetType="{x:Type Button}">
    <TextBlock x:Name="hello" Text="Hello" />
    <ControlTemplate.Triggers>
      <Trigger Value="True">
        <Trigger.Property>IsMouseOver</Trigger.Property>
        <Setter Property="Foreground" Value="Red" TargetName="hello"/>
     </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
</Button.Template></Button>
</Page>

So, what is the hidden difference between element property syntax and attribute property syntax?

  • 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-16T01:40:34+00:00Added an answer on May 16, 2026 at 1:40 am

    There shouldn’t be a difference. I think you just found a bug in the XAML parser.

    The framework has special handling for Setter, Trigger, and Condition. Check out Trigger.ReceiveTypeConverter with Reflector, which overrides the handling of property setters for the Value and Property properties. I think this is so that it can parse the Value property with a different type based on the Property property. For example, it parses “Red” as a Brush rather than just a String when it sees the Property is Foreground and that Foreground is of type Brush.

    It looks like that hook overrides all sets of properties named Value or Property within a Trigger, but that it doesn’t correctly handle the element property syntax. To see the effect, try creating a markup extension like this:

    public class Test
        : MarkupExtension
    {
        public DependencyProperty Property { get; set; }
        public DependencyProperty Property2 { get; set; }
    
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return Property ?? Property2;
        }
    }
    

    The following XAML will get the same error as your second example, and you can verify by setting a breakpoint that Property is never set:

    <Trigger.Property>
        <local:Test>
            <local:Test.Property>IsMouseOver</local:Test.Property>
        </local:Test>
    </Trigger.Property>
    

    However, this will work, because the property is not named “Property”:

    <Trigger.Property>
        <local:Test>
            <local:Test.Property2>IsMouseOver</local:Test.Property2>
        </local:Test>
    </Trigger.Property>
    

    And this will work, because it uses the attribute syntax:

    <Trigger.Property>
        <local:Test Property="IsMouseOver"/>
    </Trigger.Property>
    

    If you really need to use the element property syntax, that will give you a workaround: create a MarkupExtension that has a Property of type DependencyProperty named something other than “Property”, and return that in ProvideValue.

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

Sidebar

Related Questions

Suppose I have a UISlider interface element that I connected to a property in
I'm trying to create a schema for a <property> element which must have a
I thought that this was easier… I have a asp:hyperlink control, with target=_blank ,
I'm new to jQuery. I've searched and found some results that might work, but
I have a element that is set to contain a table element. The table
I have an iPad app that uses custom fonts though the UIAppFonts elements in
I thought that by convention, only methods with an exclamation mark altered the object.
I thought that a 32-bit process could use at most 2GB RAM, since half
I thought that a delegate instance was interchangeable with a function instance. Take the
I thought that by default my Regex would exhibit the greedy behavior that I

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.