In my WPF app, I have a Save button which needs to be enabled when a collection count is greater than 0.
I am trying to convert using ObjectDataProvider which will use Convert.ToBoolean(int value)
. (I can use a converter, but why not try learn something different today.)
So I did as below, but it does not work.
<ObjectDataProvider x:Key="Convert"
ObjectType="{x:Type sys:Convert}"
MethodName="ToBoolean">
<ObjectDataProvider.MethodParameters>
<sys:Int32>0</sys:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<Button IsEnabled="{Binding MyCollection.Count, Source={StaticResource Convert}}">
What am i missing?
Based on the link provided by Prjaval and you, i'm writing this as answer.
In your code, you are accessing, MyCollection.Count from object Boolean, so it will give binding errors and won't work.
we can achieve your requirement by, updating the method parameter of ObjectDataProvider via different source, and use the source in different binding. That means we cannot assign methodparameter and use the Source in same binding.
i tried like this and worked perfectly,
Behaviour
i used separate behaviour to update parameter.
please correct me if anything is wrong.