I'm reading JSON from a WebService and put my data in a list of textblocks (wrapped in grids).
Sometimes the text is long and I would like that the textblock would add automatically a new line if needed (instead going to the right endlessly).
I've read somewhere that I should wrap the textblock in a Label (not recognized by VS2010?)..
I cannot put <\newline> or \n or anything because I don't know where or when.
Thanks.
You could set the TextWrapping property to Wrap:-
http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.textwrapping.aspx
Add like this in your xaml
<TextBlock TextWrapping="Wrap"/>
You can set TextWrapping property of Textblock to Wrap from Designer or from XAML....
Related
How can I make the items in my FMX TListBox bold? I can't find anything by myself, either in the documentation or the Internet.
You need to set two properties for the tListItem in question. The first line of code below lets you set the font properties for that ListItem rather than having the style dictate the font properties (if you miss this step, the next step will have no affect). The second line sets that ListItem to bold (where, of course, x is the index within the list that should be made bold)
ListBox1.ListItems[x].StyledSettings:=[];
ListBox1.ListItems[x].Font.Style:=[TFontStyle.fsBold];
Thanks to Gregg who gave a working answer for delphi, i'll put a C++Builder version here.
I made a loop over my ListBox with the item count, and it does not affect the loading speed of the ListBox (around 4000 items in my case) so it's a good solution at least for me.
ListBox->ListItems[x]->StyledSettings = ListBox->ListItems[x]->StyledSettings >> TStyledSetting::Style;
ListBox->ListItems[x]->Font->Style = ListBox->ListItems[x]->Font->Style << fsBold;
You can use custom theme for TListBoxItems. Create one by right mouse on ListBox.
I have a problem to show my object field Description on Cross Platform Label . Description has many hashtag, that need to be clicked and open another page. Here is my example :
"I have some #issues that need to be #solved maybe Xamarin#Support can help me."
That is my description, and i want to put it on Label. How can i set those hashtag (#issues, #solved, #Support) to be clickable?
One option is to use a WebView and use simple HTML / CSS. This would give you the most flexibility and in some cases is the simplest.
Another option would be to write custom renderers. There are plenty of answers out there on how to do this natively but as a starting point.
On Android you need to use a TextView with autoLink="web".
On iOS, a UILabel should allow you to do this.
You can change color, ForegroundColor, FontAttributes of the hashtags by using Span in the label. Sadly, Span doesn't have GestureRecognizers.
I suggest you to stack multiple labels and add TapGestureRecognizer on the label with hashtags.
I'm trying to work out how to catch a data binding in the act (either intercept or post-process) to customize the display of data in the target control.
I know about IValueConvertor and understand that I can transform a simple value into another simple value, but I don't believe this is enough for my needs... which are:
The control in this case is a TextBlock and the data values from the objects in my ObservableCollection are variable length strings. I want to render the strings in multiple colours by splitting them into pieces and programatically creating a <Run Foreground="xxx" Text="yyy"/> for each piece inside the TextBlock.
Since the strings are variable length and the colours have to be programatically determined from the content of the string, I don't believe I can pre-create the <Run>s in the XAML, so I have to somehow get in on the data binding action and generate the <Run>s at bind-time (or very soon after).
Binding.NotifyOnTargetUpdated would seem to be a way to set up an event handler to do the work, but that's not available in the Windows Phone cut-down Silverlight implementation.
Any ideas? All search results seem to point to the above, but I'm looking for that little bit more.
Having apparently exhausted all the cut-down Silverlight on Windows Phone options for programmatically hooking the rendering of ListBoxItems via the data model, I ended up adding a Loaded="..." event handler to the XAML for the TextBlock.
It doesn't feel like the nicest solution, but perhaps that's just my code-preference talking and it's actually the right way to do it on Windows Phone.
In any case, because I'm hooked to the TextBlock directly, I'm not sure how to then get to the databound object on the ListBoxItem containing the TextBlock... if anyone has advice on how to get back up the tree to the generated ListBoxItem then I could use the bound object directly instead of retrieving it from elsewhere.
Note that since the ListBoxItem is generated, I didn't find where to put a Loaded="..." event handler for that in the XAML. The ListBox.ItemTemplate doesn't accept a Loaded attribute.
Update: this doesn't work!
The Loaded event handler fires when the TextBlock is first created and loaded, so the substitution works initially.
BUT
The generated ListBoxItem seems to be recycled (I guess by the ListBox.ItemContainerGenerator which doesn't want to use excessive amounts of memory by instantiating a whole new container when there are many off-screen entries in the list that won't need to be seen for a while) and when this happens, the Loaded event DOES NOT FIRE.
Since I modify the content when the TextBlock was first Loaded, this breaks the binding association so when the ListBoxItem is recycled, it now contains old/incorrect data.
Still no solution.
I'm thinking about trying to use an IValueConvertor and somehow pass a reference to the binding target... now sure how yet though.
Update 2: finally got it to work...
Sticking with the Loaded="..." event handler, it is possible to disable recycling of previously-generated ListBoxItems by configuring the VirtualizingStackPanel used by the ListBox under the covers.
In the XAML for the ListBox set VirtualizingStackPanel.VirtualizationMode="Standard" to force a new ListBoxItem to be generated each time instead of recycling previously-generated ones.
This means the Loaded event handler is called every time and I can replace the ordinary text of the TextBlock with the <Run>s to produce dynamically coloured text.
I've got problem with automatically breaking StackPanel into next line. Here's the sample code:
<StackPanel Orientation="Horizontal" Width="180">
<TextBlock.../>
<TextBlock.../>
<TextBlock.../>
<Image.../>
...
</StackPanel>
Now I want to achive something like this: when there is not enough space for another element in the StackPanel it should be placed in new line. How I can achive this (it's not necessary to use stackpanel)?
PS: My goal is to place text and images in one line (it can of course break, when there is not enough space for another element). Maybe you can provide better solution than using textblocks and images?
Try the WrapGrid, it should do what you want:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.wrapgrid.aspx
The only catch (which isn't a bad thing) is that WrapGrid can only display items in an ItemsControl, so use it this way (changing ListView to any ItemsControl):
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
Use VariabeSizedWrapGrid instead of StackPanel, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.variablesizedwrapgrid.aspx
For the multiple TextBlocks, consider using a single textBlock with multiple Runs. Your Image can of course not be included in the runs, but one TextBlock with two Runs is better than two consecutive TextBlocks.
UPDATE: This might actually not help you at all to get the layout you want. You may have to look at the RichTextBlock control, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.richtextblock.aspx
Out of the box, there's no WrapPanel available for WinRT. At least not for now...
However in the meantime there's a workaround... I've tested it and it works.
you can check the following links at the following link.
http://www.codeproject.com/Articles/24141/WrapPanel-for-Silverlight-2-0
Since WrapPanel inherits from Panel class, you can create a WrapPanel or simply use the
the WrapPanel.cs code you'll find in the above SLV 2 app.
then simply include similar code
xmlns:wrapPanel="using:yourWinRTApp"
....
<wrapPanel:WrapPanel Orientation="Horizontal" Width="400" >
....
</wrapPanel:WrapPanel>
it should do the trick ...
Info taken from:
http://www.michielpost.nl/PostDetail_75.aspx
You might use GridView, it have similar layout-behavior as the WrapPanel.
I feel kind of silly asking this question as it seems really simple, but how do I create a text box that I can type in instructions and stuff like that. I don't need the user to be able to change it, it is just to give instructions. I tried the label, but it only allows one line. I need something that can allow about a paragraph or so. Similar to the box in an installer that describes what the program does. What did I miss?
You can use a label but set its AutoSize property to false. This allows you to size the label as you wish and it will automatically wrap the text to fit.
You can also anchor the label to the parent form to have it automatically resize and reflow the text if the user resizes the parent form.
You want a text box, but set its Read Only property to TRUE, and maybe Enabled to FALSE