Based on the link provided by Prjaval and you, i'm writing this as answer.
<Button IsEnabled="{Binding MyCollection.Count, Source={StaticResource Convert}}">
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,
<Grid>
<Grid.Resources>
<ObjectDataProvider x:Key="convert"
MethodName="ToBoolean"
ObjectType="{x:Type sys:Convert}">
<ObjectDataProvider.MethodParameters>
<sys:Int32>0</sys:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--Updating Parameter-->
<ItemsControl ItemsSource="{Binding Groups}">
<i:Interaction.Behaviors>
<local:ObjectDataUpdate>
<local:ObjectDataUpdate.Count>
<Binding BindsDirectlyToSource="True"
Mode="OneWayToSource"
Path="MethodParameters[0]"
Source="{StaticResource convert}" />
</local:ObjectDataUpdate.Count>
</local:ObjectDataUpdate>
</i:Interaction.Behaviors>
</ItemsControl>
<!--Using ObjectDataProvider-->
<Button Height="40" Grid.Row="1" IsEnabled="{Binding Source={StaticResource convert}}" />
</Grid>
Behaviour
public class ObjectDataUpdate : Behavior<ItemsControl>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.Loaded += (_, __) =>
{
//Some logics to update Count. I'm setting directly for sample purpose
Count = AssociatedObject.Items.Count;
};
}
public int Count
{
get { return (int)GetValue(CountProperty); }
set { SetValue(CountProperty, value); }
}
// Using a DependencyProperty as the backing store for Count. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CountProperty =
DependencyProperty.Register("Count", typeof(int), typeof(ObjectDataUpdate), new PropertyMetadata(0));
}
i used separate behaviour to update parameter.
please correct me if anything is wrong.