-2

I have come back to this question to flag it as a duplicate as its essence was how to set up a basic data binding, which has been answered many times, here is one of the good answers: (I would delete this question if I could)

WPF: simple TextBox data binding

1
  • Sometimes it's helpful to read a book or an article about the essentials of a technology before trying to use it. For WPF data binding I'd suggest to read the Data Binding Overview article on MSDN for a basic understanding. Commented Sep 19, 2016 at 21:21

1 Answer 1

1

Your problem is that you are trying to bind to a Method instead of a property. Try something like this:

public static bool fruitLimits
{
    get
    { /*your method code here*/ }
}

EDIT: There is no way to pass arguments into the Property, so if you don't have access to the values of the text box you may have to write a converter that gets these values passed. Here the basics: link You can pass one object as the value and the other as the parameter. The converter then processes the information and returns a bool. Here an example of what the Binding of this Converter should look like:

Here an example, your binding should look something like this:

                <DataTrigger Value="True">
                    <DataTrigger.Binding>
                        <MultiBinding Converter="{StaticResource converterKey}">
                            <Binding ElementName="boxVariable" />
                            <Binding ElementName="textboxDec" Path="Text" />
                        </MultiBinding>
                    </DataTrigger.Binding>

Replace the "ElementName=boxVariable" and "ElementName=textboxDec" with the names of the controls you want to pass. You may have to add "Path=Text" on the textbox binding.

Then in the IMultiValueConverter do something like this:

public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    if (value[0].GetType().Equals(typeof(ComboBox)) && value[1].GetType().Equals(typeof(String)))
    { 
        ComboBox boxVariable = value[0] as ComboBox;
        string textboxDec = value[1] as String;

        /* your method code here, returns Boolean */
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Could you give an example of a converter ? - will it use the result from my method fruitLimits? and then how would it be passed to the property
Hi R.jauch thanks for the continuing help, for the DataTrigger it says, A'Binding' cannot be set on the 'ConverterParameter' property of type 'Binding'. A 'Binding' can only be set on a DependecyProperty of a DependencyObject
Updated my answer to use a MultiValueConverter, now you should be able to bind to both controls

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.