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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:47:50+00:00 2026-05-28T04:47:50+00:00

In my Silverlight prjoect I am creating a simple two-way binding in code: This

  • 0

In my Silverlight prjoect I am creating a simple two-way binding in code:

This is the property I want to bind to:

public class Selection : ViewModelBase {

    private string selectedModel;

    public string SelectedModel {
        get { return selectedModel; }
        set {
            selectedModel = value;
            FirePropertyChanged("SelectedModel");
        }
    }
}

My binding target is the text property of a rich text box.

My binding code is the following:

Selection s = getSelectionObject();

Binding modelBinding = new Binding("SelectedModel");
modelBinding.Source = s.SelectedModel;
selectorContent.usc_ModelSelector.SetBinding(GSelector.TextProperty, modelBinding);

That works fine! Every time the SelectedModel property of the Selection object changes, the rich text box is getting notified and updated accordingly. But it’s only bound one-way and I need it bound two-way. So i have tried to change the binding mode by altering the above code:

Binding modelBinding = new Binding("SelectedModel");
modelBinding.Path = new PropertyPath(s.SelectedModel);
modelBinding.Source = s.SelectedModel;
modelBinding.Mode = BindingMode.TwoWay;
selectorContent.usc_ModelSelector.SetBinding(GSelector.TextProperty, modelBinding);

But that doesn’t work. It compiles but the whole binding now seems to be without effect. Not only that I can’t trigger a change in the ViewModel (in the Selection class in the SelectedModel property – which should be the effect when two-way binding would work correctly) when changing the text of the RichTextBox, I even can’t see the one-way binding wokring any more which worked with the above code!

It seems that the line

modelBinding.Path = new PropertyPath(s.SelectedModel);

is the source of the problem because when I set s.SelectedModel as the bindings Path property then the Path property of the modelBinding object seems to have the correct value (which revealed a look inside the object during runtine while debugging – it is a string value) but I can’t see any change in the rich text box.

Restoring the code to the one-way binding version immediately makes the rich text box work again as it should.

Can anyone help ? I already spent several hours in this and i really have to catch a customer’s deadline .. So any help would be highly appreciated 🙂 Many thanks in advance …

  • 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-28T04:47:51+00:00Added an answer on May 28, 2026 at 4:47 am

    This:

    new Binding("SelectedModel");
    

    Creates a new binding with the path "SelectedModel". Then you go on to overwrite the correct path with this line:

    modelBinding.Path = new PropertyPath(s.SelectedModel);
    

    Which is not going to work; The constructor reference states:

    A property path that either describes a path to a common language runtime (CLR) property, or a single dependency property.

    So either use a string or a reference to a DP.

    Anyway, i do not think that you need that line at all because you already set the path correctly in the binding constructor.

    Edit: Your source is wrong!

    The source should be the object containing the property, here that is s.

    Binding modelBinding = new Binding("SelectedModel");
    modelBinding.Source = s;
    modelBinding.Mode = BindingMode.TwoWay; // This might be optional depending on the default mode of the target property
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing for Silverlight 4.0 and after mostly creating class libraries with
Is there a way to do this? I have a library with 'helper' code
I made a Silverlight project like this: <UserControl x:Class=silverlighttest3.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 mc:Ignorable=d
This is a for a Silverlight project that isn't anchored to an .aspx file,
I want to debug my silverlight project in IE and debug other ASP.Net projects
Given i have a class like so in my Data Layer public class GenericRepository<TEntity>
I have a problem in silverlight which I need to convert this image(from database
When creating a test project for a Silverlight MVVM application, should I create a
After creating a Azure Project within my silverlight app and adding the existing service
Project Structure I have a silverlight project SLProj, that references a silverlight class library

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.