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)
-
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](https://msdn.microsoft.com/en-us/library/ms752347(v=vs.110).aspx) article on MSDN for a basic understanding. – Clemens Sep 19 '16 at 21:21
1 Answers
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 */
}
}

- 103
- 4
-
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 – JohnChris Sep 19 '16 at 15:32
-
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 – JohnChris Sep 21 '16 at 09:00
-
Updated my answer to use a MultiValueConverter, now you should be able to bind to both controls – R.jauch Sep 21 '16 at 10:39