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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:41:01+00:00 2026-05-26T05:41:01+00:00

I’m currently building a bunch of common use controls which basically just extend the

  • 0

I’m currently building a bunch of common use controls which basically just extend the default Silverlight controls by adding a label and stuff like that… But I’m having a hard time getting some bindings to work… Below are some examples of what currently doesn’t work:

UPDATE:

Here’s some more context to help understand the problem:

public class ComboboxField : Field
{

    public string SelectedValuePath
    {
        get { return (string)this.GetValue(SelectedValuePathProperty); }
        set { this.SetValue(SelectedValuePathProperty, value); }
    }
    public static readonly DependencyProperty SelectedValuePathProperty =
    DependencyProperty.Register("SelectedValuePath", typeof(string), typeof(ComboboxField), new PropertyMetadata(string.Empty));


    public string DisplayMemberPath
    {
        get { return (string)this.GetValue(DisplayMemberPathProperty); }
        set { this.SetValue(DisplayMemberPathProperty, value); }
    }
    public static readonly DependencyProperty DisplayMemberPathProperty =
      DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ComboboxField), new PropertyMetadata(string.Empty, null));



    public IEnumerable ItemsSource
    {
        get { return (IEnumerable)this.GetValue(ItemsSourceProperty); }
        set { this.SetValue(ItemsSourceProperty, value); }
    }

    public static readonly DependencyProperty ItemsSourceProperty =
    DependencyProperty.Register("ItemsSource", typeof(Object), typeof(ComboboxField), new PropertyMetadata(new List<object>()));



    public object SelectedValue 
    {
        get { return (object)GetValue(SelectedValueProperty); }
        set { SetValue(SelectedValueProperty, value); }
    }

    public static readonly DependencyProperty SelectedValueProperty =
        DependencyProperty.Register("SelectedValue", typeof(object), typeof(ComboboxField), new PropertyMetadata(null, (s, e) => { s.SetValue(Field.ValueProperty, SelectedValueProperty);}));

    #region Ctors
    public ComboboxField(FieldDescription fieldDescription, Form parentForm) : base(fieldDescription, parentForm)
    {
        this.Template = Application.Current.Resources["ComboBoxDefaultTemplate"] as ControlTemplate;
    }

    public ComboboxField() : base(new FieldDescription(Guid.NewGuid(), "ComboboxField1", FieldType.Collection), null)
    {
        this.Template = Application.Current.Resources["ComboBoxDefaultTemplate"] as ControlTemplate;
    }
    #endregion

}

The Control Template: (removed some of the irrelevant stuff)

<ControlTemplate x:Name="ComboBoxDefaultTemplate" TargetType="my:ComboboxField">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{TemplateBinding LabelColumnWidth}" />
                    <ColumnDefinition Width="{TemplateBinding FieldColumnWidth}" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Style="{TemplateBinding TitleStyle}" Text="{TemplateBinding Title}"></TextBlock>
                <TextBlock Text="*" Grid.Row="0" Grid.Column="0" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Required, Converter={StaticResource boolToVisibility}}" Width="5" />
                <TextBlock Grid.Row="1" Grid.Column="0" Style="{TemplateBinding SummaryStyle}" Text="{TemplateBinding Summary}" Grid.ColumnSpan="2"></TextBlock>
<ComboBox Style="{TemplateBinding FieldStyle}" Grid.Row="0" Grid.Column="1"
                          ItemsSource="{TemplateBinding ItemsSource}" 
                          SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedValue, Mode=TwoWay}" 
                          SelectedValuePath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedValuePath, Mode=TwoWay}" 
                          DisplayMemberPath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DisplayMemberPath, Mode=TwoWay}"></ComboBox>
            </Grid>
        </ControlTemplate>

The way I’m trying to use it:

<cc:ComboboxField Grid.Row="10" TitleStyle="{StaticResource labelStyle}" 
                                  Title="Countries" ItemsSource="{Binding Countries}" 
                                  SelectedValuePath="CountryId" DisplayMemberPath="CountryId" 
                                  SelectedValue="{Binding Path=SelectedCountry, Mode=TwoWay}" />

What am I doing wrong here?

  • 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-26T05:41:02+00:00Added an answer on May 26, 2026 at 5:41 am

    I can see immediately a couple of problems with your dependency properties.

    Firstly, I have a Golden Rule for working with dependency properties, which your code violates:

    The CLR property getter must contain only a call to GetValue and the setter must contain only a call to SetValue.

    For example, the SelectedValuePath property should look like the following:

    public string SelectedValuePath
    {
        get { return (string)this.GetValue(SelectedValuePathProperty); }
        set { this.SetValue(SelectedValuePathProperty, value); }
    }
    

    Silverlight doesn’t call your property if it wants to change the value of the dependency property using binding, animation or styles. If you drop breakpoints on any of the setters, you’ll find they won’t get hit as often as you might expect.

    You can bind together two dependency properties without the class on either end needing to implement INotifyPropertyChanged. I assume your NotifyPropertyChanged method is firing the PropertyChanged event, which you should be able to remove.

    Also, if you want the Value property set to the value of the SelectedValue property every time the latter changes, you’ll need to add a PropertyChangedCallback to the SelectedValue dependency property.

    Secondly, the dependency property registrations for SelectedValuePathProperty, DisplayMemberPathProperty and ItemsSourceProperty are wrong. They all specify their owner class as Field when they are owned by the ComboboxField class instead.

    Finally, you say that you are

    having a hard time getting some bindings to work

    You’re not telling us exactly what your problem is. What are you expecting the code to do and what is it actually doing? Given that I don’t have your Form, Field and FieldDescription classes nor your FieldType enum, I can’t run your code, so I can’t really help you any more.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.