List box in c# windows phone 7 - c#

Does list box allow placing a paragraph of word into it instead of a item one after another?

I think you just need to put a text block inside a scroll viewer, but this article shows how to make a control:
See this article

This is some code that does the basic work:
<ScrollViewer x:Name="MyScroller">
<TextBlock x:Name="MyTextBlock" TextWrapping="Wrap" Text="Some very long text here..." />
</ScrollViewer>
You'll see that if the area containing the text is bigger than the size of the textblock, you'll be able to scroll to view all text.

Related

Notebook-like background for a TextBox in a Windows Phone App

I am trying to create an application to take notes for windows phone 8.1
I want to give the user,a notebook type of feel.
For this I have created the UI for notes, the XAML is:
<Grid Margin="0,12.333,0,-0.333">
<Grid.Background>
<ImageBrush ImageSource="Images/notebookpaper.jpg"/>
</Grid.Background>
<TextBox TextWrapping="Wrap" Background="{x:Null}" Text="" BorderBrush="{x:Null}" HorizontalAlignment="Left" Margin="60,96,0,0" VerticalAlignment="Top" Height="480" Width="340" BorderThickness="0" GotFocus="TextBox_GotFocus" LostFocus="TextBox_LostFocus" FontFamily="Arial" TextChanged="TextBox_TextChanged" AcceptsReturn="True" FontSize="24.8"/>
<TextBlock Text="Date : " HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Margin="246,10,0,0" Height="20" Width="59"/>
</Grid>
The image notebookpaper.jpg looks like this:
When user types in the text in text box, it looks like:
The problem is that, some characters appear a little above the line, some exactly on the line etc. which looks odd. Also, when I try to scroll, UI appears as:
The text appears striked out, as only the text scrolls and not the background image.
Also I want to be able to provide user a list of 5-6 fonts out of which they can select which one to use for typing the notes.
What should I do, so that the text appears properly aligned and text scrolls properly.
Is there any other way to do this ?
It looks like you have two problems:
Varying line height
Scrolling doesn't match the lines
To solve the first problem, you can probably work with TextBlock.TextLineBounds, talked about a bit in this MSDN blog post and the TextLineBounds enumeration documentation. This only seems to apply to TextBlocks, so you might have to swap between a TextBlock and TextBox as users edit their text.
To solve the second problem, the TextBox styles and templates page has a lot of helpful info. It looks like you can make your ImageBrush the background of your control by overriding TextBoxButtonBackgroundThemeBrush. If that doesn't work when focused, you may have to take the entire template given on the linked page and edit it to put your image in the background (there's a lot of XAML, but you should just be able to put your image in BackgroundElement or just before it).
If it still doesn't scroll, you can try setting ScrollViewer.Background instead; if that doesn't work, you'll need to handle the ScrollViewer.ViewChanging or ScrollViewer.ViewChanged events (probably by overriding it) so that it you can transform the background image by the amount of pixels the scrollviewer has moved.
You can also find the ScrollViewer in your code-behind (and skip dealing with the template) by using VisualTreeHelper. This would allow you to set the background of the ScrollViewer and/or subscribe to its events. This however is more brittle than the other methods and is usually a last resort.

How to create Image in runtime in windows phone?

I am trying to create custom menu which consists of text at least 2 textblock in one rectangle, which will act as button, For that purpose, May be converting the text into Image may be good idea to implement and serve my purpose to. so I want and Idea or code to create image during runtime, any suggestion ? If you have any sample code or link to refer??
if by "2 textblock in one rectangle" you mean text in two lines then try this
<Button>
<StackPanel>
<TextBlock Text="ABC"/>
<TextBlock Text="DEF"/>
</StackPanel>
</Button>

Copying Xaml RichTextBlock text with InlineUIContainers

I am working with some RichTextBlock objects that contain InlineUIContainer elements. I would like to be able to select and copy all of the text including the text contained in the InlineUIContainer.
Currently, when I select all of the text in the block, the text contained in the InlineUIContainer objects are skipped.
Here is an example of what I'm creating:
<RichTextBlock IsTextSelectionEnabled="True">
<Paragraph FontSize="20">
<Bold>This text is selectable</Bold>
<InlineUIContainer FontFamily="Global User Interface">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="11" VerticalAlignment="Top" Margin="0,0,-1,0">Super Script Text</TextBlock>
<HyperlinkButton ClickMode="Release" Style="{StaticResource NoMarginHyperlinkButtonStyle}">
Link
</HyperlinkButton>
</StackPanel>
</InlineUIContainer>
This text is also selectable
</Paragraph>
</RichTextBlock>
If I select all of the text from this piece of Xaml and copy/paste it in NotePad, I don't get the Super Script Text or the Link text.
Is there any way to get all of the text selected?
This is because HyperlinkButton is not part of the document API and in fact a UIElement wrapped in InlineUIContainer. There are 2 ways to handle this.
Switch to Windows 8.1 and Hyperlink which inherits from TextElement and copy will work just fine.
This is the hard way, if you must support this in Windows 8.
Remove the default Context menu items for the RichTextBlock and replace with your own Copy Command. Which should get the 2 TextPointers i.e. RichtextBlock.SelectionStart and RichTextBlock.SelectionEnd
Now with WPF we could get a TextRange within this range but winRT does not expose it, so you will need to do it in your code...
Get all the block within the RichTextBlock, and iterate through each to check if it's ContentStart and ContentEnd is within the RTB.SelectionStart and RTB.SelectionEnd if so then add them to a list.
Now it should be easy to extract all the Runs and Bold/Italics from this list and any InlineUIContainers hosting HyperlinkButtons.
2 This is not really a good way to go as it will be hard to allow for margins etc. on Paragraphs etc.

Scrolling issues in a TextBox used inside a ListBox

Since TextBox doesn't allow smooth scrolling, I've used it as a ListBoxItem. It works great. But when I enter many lines, the cursor goes out of the view, down below the list box, because of it I'm unable to see the text which I am typing. To see the cursor, I have to manually swipe the TextBox up.
Here's the code:
<ListBox>
<ListBox.Items>
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Width="467"
AcceptsReturn="True"
MinHeight="300"
MaxHeight="Infinity"
/>
</ListBox.Items>
</ListBox>
Don't set the height of the TextBox and wrap a ScrollViewer around your TextBox. That has worked for me!
Did you try the srollable textblock instead of textbox..For more details
visit http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx

WPF highlighting

Anyone has any idea how to highlight in a textblock?
Basically i have 2 textblock and both have the same string. When I highlight part of the string in one of the textblock, the other textblock shows the same highlighted part as well. I am basically stuck at how to do the highlighting.
Thanks in advance
Do you have a TextBlock or a TextBox? I'm going to assume it's a TextBox, since TextBlock does not support text selection.
In that case, you can simply use data binding to keep this in sync.
<TextBox Name="text1" />
<TextBox Name="text2"
SelectionStart="{Binding Path=SelectionStart, ElementName=text1}"
SelectionLength="{Binding Path=SelectionLength, ElementName=text1}" />
This should ensure that the same area of text is selected in text2 when the user selects it in text1 and vice-versa.
EDIT See this answer for instructions on how to bind to these properties.
If you create a custom TextBox as described in the linked answer, your code would look something like this:
<SelectionBindingTextBox Name="text1" />
<SelectionBindingTextBox Name="text2"
BindableSelectionStart="{Binding Path=BindableSelectionStart, ElementName=text1}"
BindableSelectionLength="{Binding Path=BindableSelectionLength, ElementName=text1}" />

Categories