ObjectDataProvider MethodParameter define directly in XAML
I am trying to modify the MethodParameter directly in the XAML. I do have a working example where I am setting it from code. Code version is:
Dim odp As New ObjectDataProvider()
odp = FindResource("Products")
odp.MethodParameters.Clear()
odp.MethodParameters.Add(CType(txtCatId.Text, Integer))
ObjectDataProvider defined in XAML looks like this:
<ObjectDataProvider x:Key="Products"
ObjectInstance="{StaticResource ProductsDataProvider}"
MethodName="GetProdsByCatID">
<ObjectDataProvider.MethodParameters>
<sys:Int32>0</sys:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
Is there anyway I can retrieve the value of my textbox (which is bound to a separate ObjectDataProvider and put that in place of the hardcoded "0" currently in my XAML? I 开发者_开发百科am looking to have this be completely XAML driven and have not been able to get it working without the code change.
Thanks!
You can try to bind TextBox.Text like this
<ObjectDataProvider x:Key="Products"
ObjectInstance="{StaticResource ProductsDataProvider}"
MethodName="GetProdsByCatID">
<ObjectDataProvider.MethodParameters>
<sys:Int32>0</sys:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<TextBox Text={Binding Source={StaticResource Products}, Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource"}/>
if you have other bindings to TextBox.Text try to user MultiBinding
<TextBox>
<TextBox.Text>
<MultiBinding Converter="...">
<Binding Source="{StaticResource Products}", Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
...
</MultiBinding>
</TextBox.Text>
</TextBox>
精彩评论