Question

I have a simple User Control:

 public partial class FreqSpreadUC : UserControl
{
    public FreqSpreadUC()
    {            
        InitializeComponent();  
        FreqOne = "trying to pass this on to the parent";
    }

    public String FreqOne
    {
        get { return (String)GetValue(FreqOneProperty); }
        set { SetValue(FreqOneProperty, value); }
    }

    // Using a DependencyProperty as the backing store for FreqOne.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty FreqOneProperty =
        DependencyProperty.Register("FreqOne", typeof(String), typeof(FreqSpreadUC));



}

Then I am consuming it as follows:

  <spread:FreqSpreadUC FreqOne="{Binding TestFreqOne}" />

When the underlying user control changes its FreqOne dependency property, I want TestFreqOne to change as well. I am trying to create a user control that will "output" a result to the parent control. How would I go about doing this? Thank you.

Was it helpful?

Solution

Your question title already suggests it. You need a two-way binding:

<spread:FreqSpreadUC FreqOne="{Binding TestFreqOne, Mode=TwoWay}" />

Alternatively you might register property metadata with your dependency property that makes it bind two-way by default:

public static readonly DependencyProperty FreqOneProperty =
    DependencyProperty.Register(
        "FreqOne", typeof(String), typeof(FreqSpreadUC)
        new FrameworkPropertyMetadata(
            null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top