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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:54+00:00 2026-05-14T00:33:54+00:00

I am trying to create an attached behavior that can be applied to a

  • 0

I am trying to create an attached behavior that can be applied to a Silverlight ComboBox.

My behavior is this:

using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace AttachedBehaviours
{
    public class ConfirmChangeBehaviour 
    {

        public static bool GetConfirmChange(Selector cmb)
        {
            return (bool)cmb.GetValue(ConfirmChangeProperty);
        }

        public static void SetConfirmChange(Selector cmb, bool value)
        {
            cmb.SetValue(ConfirmChangeProperty, value);
        }


        public static readonly DependencyProperty ConfirmChangeProperty =
            DependencyProperty.RegisterAttached("ConfirmChange", typeof(bool), typeof(Selector), new PropertyMetadata(true, ConfirmChangeChanged));
        public static void ConfirmChangeChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            Selector instance = d as Selector;

            if (args.NewValue is bool == false)
                return;

            if ((bool)args.NewValue)
                instance.SelectionChanged += OnSelectorSelectionChanged;
            else
                instance.SelectionChanged -= OnSelectorSelectionChanged;

        }

        static void OnSelectorSelectionChanged(object sender, RoutedEventArgs e)
        {
            Selector item = e.OriginalSource as Selector;

            MessageBox.Show("Unsaved changes. Are you sure you want to change teams?");    

        }

    }

}

This is used in XAML as this:

<UserControl x:Class="AttachedBehaviours.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:this="clr-namespace:AttachedBehaviours"
             mc:Ignorable="d">
    <Grid x:Name="LayoutRoot">
        <StackPanel>
            <ComboBox ItemsSource="{Binding Teams}" 
                      this:ConfirmChangeBehaviour.ConfirmChange="true" >
            </ComboBox>
        </StackPanel>
    </Grid>
</UserControl>

I am getting an error:

Unknown attribute ConfirmChangeBehaviour.ConfirmChange on element ComboBox. [Line: 13 Position: 65]

Intellisense is picking up the behavior, why is this failing at runtime?

Thanks,
Mark

EDIT: Register() changed to RegisterAttached(). Same error appears.

  • 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-14T00:33:55+00:00Added an answer on May 14, 2026 at 12:33 am

    You’ve misregistered your attached property

    public static readonly DependencyProperty ConfirmChangeProperty =
            DependencyProperty.RegisterAttached("ConfirmChange", typeof(bool), typeof(Selector), new PropertyMetadata(true, ConfirmChangeChanged));
    

    Should be

    public static readonly DependencyProperty ConfirmChangeProperty =
            DependencyProperty.RegisterAttached("ConfirmChange", typeof(bool), typeof(ConfirmChangeBehaviour), new PropertyMetadata(true, ConfirmChangeChanged));
    

    May I advise you to move over to using the Blend Interactivity Behaviours. Writing XAML as opposed to using a tool never makes Designers happy.

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

Sidebar

Related Questions

I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a sitemap using Linq to Xml, but am getting an
I am trying to create a wrapper on Linux which controls how many concurrent
I'm trying to determine if Attached Behaviors are something we need in building controls
I'm trying to create a server control, which inherits from TextBox, that will automatically
I am getting this error in rails whenever i am trying to create an
I'm creating a site where user can create a node with multiple images attached.

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.