I have defined on my ViewModel class a static property named
static member GetColumnTypes = FSharpType.GetUnionCases typeof<ColumnType>
where ColumnType is a normal union type
type ColumnType = T_Link of TableName | T_Real | T_Bool | T_Int | T_String
I don't understand the logic at play in XAML to bind to such a collection in the following scenarios :
<UserControl.Resources>
<ObjectDataProvider x:Key="typelist" MethodName="GetColumnTypes" ObjectType="{x:Type local:MarkupViewModel}"/>
<local:MarkupViewModel x:Key="defaultVM" d:IsDataSource="True"/>
</UserControl.Resources>
//1-WORKS
<ComboBox ItemsSource="{Binding Source={StaticResource defaultVM}, Path=GetColumnTypes}"></ComboBox>
//2-DOES NOT WORK
<ComboBox ItemsSource="{Binding Source={StaticResource typelist}}"></ComboBox>
//3-DOES NOT WORK
<ComboBox ItemsSource="{Binding Source={x:Type local:MarkupViewModel}, Path=GetColumnTypes}"></ComboBox>
//4-WORKS
<ComboBox ItemsSource="{Binding Path=GetColumnTypes}" />
- Why does this work ? I though the static ressource named
defaultVM
was creating an object using the parameterless constructor. On this object, there is no method GetColumnTypes ! - Why does it not work ? I thought I was calling
GetColumnTypes
on the type specified. and if I look at example getting Enum values, it seems to be what is happening. my case is jsut simpler as it has no parameters - Again, does this not call he method on the mentionned type ?
- Here I set the datacontext to an instance of my Viremodel, and it 'magically' knows hos to go from the instance to a static method.
Beside those questions, I feel like it is very much black box magic, and I see very little information about the binding process.
What is the best approach to make it clear ?
Are there may be some debugging tool available for the Binding process ?