I want to add data from 2 columns from a datagrid and display them using a single tooltip. I am able to achieve the result from 1 column only but when I try to concatenate the values doesn't show up.
<TextBlock Text="{Binding Message, Mode=OneWay}" Margin="4 0"
VerticalAlignment="Center" HorizontalAlignment="Stretch" >
<ToolTip>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding RelativeSource="{RelativeSource Self}" Path="SourceName"/>
<Binding RelativeSource="{RelativeSource Self}" Path="Message"/>
</MultiBinding>
</ToolTip>
</TextBlock>
SourceName and Message are the values extracted from properties.
How do I show both of them in a single Tooltip ?
ToolTip should be a part of the TextBlock element
<TextBlock Text="{Binding Message, Mode=OneWay}" Margin="4 0"
VerticalAlignment="Center" HorizontalAlignment="Stretch" >
<TextBlock.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="SourceName"/>
<Binding Path="Message" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
Probably, the bindings should be also changed if you want to get information from the DataContext and not from the visual element.
Related
I am writing a WPF application, which is then translated using VisualLocBaml. VisualLocBaml works mostly fine and allow me to translate all relevant strings, except for the StringFormat I use for a multibinding.
Here is the XAML portion of the code that has the multibinding:
<TextBlock x:Uid="TextBlock_3" TextAlignment="Center" FontSize="24">
<TextBlock.Text>
<MultiBinding x:Uid="MultiBinding_1" StringFormat="Your ladder position at {0} is {1}">
<Binding x:Uid="Binding_1" Path="localInfos.Town" />
<Binding x:Uid="Binding_2" Path="userInfos.Pos" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
I tried adding some Localization attribute as described here : https://msdn.microsoft.com/en-us/library/ms753944(v=vs.110).aspx, like this:
<TextBlock x:Uid="TextBlock_3" TextAlignment="Center" FontSize="24" Localization.Attributes = "$Text(Modifiable Readable)">
<TextBlock.Text>
<MultiBinding x:Uid="MultiBinding_1" StringFormat="Your ladder position at {0} is {1}" Localization.Attributes = "$StringFormat(Modifiable Readable)">
<Binding x:Uid="Binding_1" Path="localInfos.Town" />
<Binding x:Uid="Binding_2" Path="userInfos.Pos" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
But it didn't help: the StringFormat "Your ladder position at {0} is {1}" is still the only relevant string that is not available to translate in Visual LocBaml
I am writing the below code for implementing a Multibinding in WPF textblock
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}-{1}">
<Binding Source="{Binding Path=localResource.bookdata_labelPageNO,Source={StaticResource LanguageManagerDynamic}}"/>
<Binding Path="PageNo"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
I am trying to load a string like "Page xx" where xx is the page number which is a property of the binded model and the string "Page" is loaded from the resource
But i am getting runtime error on this line # XAML . What is causing the error ?
This was my previous working code
<TextBlock Text="{Binding PageNo,StringFormat=page. {0}}" />
Can You try Like this
<TextBlock>
<Run Text="Page" />
<Run Text="{Binding PageNo}" />
</TextBlock>
Ok for pure xaml solution you can do this, assuming your resources are loaded properly.
<Window.Resources>
<sys:String x:Key="Page">Page</sys:String>
</Window.Resources>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Source="{StaticResource Page}"/>
<Binding Path="PageNo" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
I have a textbox in WPF and I need to display text in xxx-xxx-xxxx format.
<TextBox FontSize="30" Text="{Binding MyString,UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" MaxLength="10"></TextBox>
MyString is just property which sets value in TextBox into it for some other logic. Can I do it in XAML itself usng StringFormat?
You can try using the MaskedTextBox to specify the format of the input.
Example:
<wpfx:MaskedTextBox Mask="000-000-0000" />
Try this tutorial also.
As an option you could split the text in the code behind (or View Model) and bind each value separately
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{0}-{1}-{2}">
<Binding Path="FirstPart" />
<Binding Path="SecondPart" />
<Binding Path="ThirdPart" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Yes you can do this. Try the following:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}-whateverhercomes-andwhateverherecomes">
<Binding Path="MyString"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
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.
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.
I have a ListView which gives me correct information. I want to apped at the end of each row, two TextBoxes in which user can edit, can anyone guide me?
This is the result I want to see John Smith textbox textbox.
Here is my code below:
<ListView.ItemTemplate>
<DataTemplate>
<Label x:Name="lblPerson">
<Label.Content>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="FName" />
<Binding Path="LName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Label.Content>
</Label>
</DataTemplate>
</ListView.ItemTemplate>
I don't know if I understand correctly what your problem is, but inside the DataTemplate you can use a StackPanel or a DockPanel and place the Label and anything else you can, something like this:
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label x:Name="lblPerson">
<Label.Content>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="FName" />
<Binding Path="LName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Label.Content>
</Label>
<TextBox Text="Something">
<TextBox Text="{Binding SomeField}">
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
Is this what you are asking? Regards