Reputation: 846
I cannot figure out my MultiBinding StringFormat behavior. I have a DataContext which defines a numeric range via the properties MinIncl and MaxIncl. I want to create a tooltip using MultiBinding to create a tip like "1.0 to 999.0". I try the following code:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:F1} to {1:F1}">
<Binding Path="SelectedTrainingScriptParameter.MinimumInclusive"/>
<Binding Path="SelectedTrainingScriptParameter.MaximumInclusive"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
The resulting tooltip is "to 999.0 1.0". So it has reversed the range and put the word "to" first.
If I remove the spaces and try "{}{0:F1}to{1:F1}", I get the right answer: "1.0to999.0".
Seriously, why does the whitespace and word "to" break this thing?
Thanks.
-reilly.
Upvotes: 2
Views: 2355
Reputation: 23290
In this case you don't need a multi, just use the same TextBlock
instead like;
<TextBlock>
<Run Text="{Binding Path=SelectedTrainingScriptParameter.MinimumInclusive}"/>
<Run Text="to"/>
<Run Text="{Binding Path=SelectedTrainingScriptParameter.MaximumInclusive}"/>
</TextBlock>
Or if you really want to use it as is;
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} to {1}">
<Binding Path="SelectedTrainingScriptParameter.MinimumInclusive" />
<Binding Path="SelectedTrainingScriptParameter.MaximumInclusive" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
As to the weird whitespace thing, no idea sorry. Hope this helps, cheers.
Upvotes: 3