Hello,
using visual studio c# 2010 and WPF, I have a TextBox that will be either set by a method exposed as an ObjectDataProvider, or manually set by the end user.
Moreover, this value will be used as an input for another method exposed as another ObjectDataProvider.
I have implemented this kind of behavior on different components, but I have trouble combining everything together.
my method looks like this:
<ObjectDataProvider x:Key="UISpotProvider" ObjectType="{x:Type uilayercommon:UISpotProvider}"/>
<ObjectDataProvider x:Key="Spot"
ObjectInstance="{StaticResource UISpotProvider}"
MethodName="getSpot">
<ObjectDataProvider.MethodParameters>
<system:String>Parameter1</system:String>
<system:DateTime>2011-12-12</system:DateTime>
<system:String>EUR/USD</system:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
it returns an object of type UISpot whose member String MID I wish to display in my TextBox.
which I was doing this way:
<TextBox Name="textBoxSpot" DataContext="{Binding Source={StaticResource Spot}}" Text="{Binding Path=MID}" >
this works fine.
now what I want to do, is to use the value in my textbox "textBoxSpot", which may have been overwritten by the end user, as an input to various methods or component.
I did that in another component using the MultiBinding, and I got something like this:
<MultiBinding Converter="{StaticResource CcyPairMultiConverter}" Mode="OneWayToSource">
<Binding ElementName="comboBoxInstrument" Path="SelectedItem" Mode="OneWayToSource" />
<Binding Source="{StaticResource Spot}" Path="MethodParameters[2]" BindsDirectlyToSource="True" Mode="OneWayToSource" />
<Binding Source="{StaticResource PriceUnit}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource" />
which is working fine too.
So I tried the same thing with my TextBox, many ways without success, and finaly it looks like this:
<TextBox.Text>
<MultiBinding Converter="{StaticResource SpotMultiConverter}">
<Binding Source="{StaticResource Spot}" Mode="OneWay" />
<Binding ElementName="textBoxSpot" Path="Text" Mode="OneWayToSource" />
</MultiBinding>
</TextBox.Text>
The SpotMultiConverter looks like this:
public class UISpotMultiConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((UISpot)values[0]).MID;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
{
return new object[] { };
}
return new object[]
{
value,
};
When I set the textbox manually, I see the value going through the ConvertBack, and when it is set via the Spot provider, I see the UISpot in value[0] but I just can get to display it in the textbox. I tried returning it as a String, as an Object, using Path. At this point I don't know what to do.
Any help would be much appreciated,
Cheers!