I have some text in a ScrollViewer control written in c# code, how do I wrap the text? Any solution?
Initialy I have a pop-up, inside this a stack panel and added
ScrollViewer sv = new ScrollViewer();
In this scroll viewer i put some text.
string values[]= new string[]; //(example)
sv.Content = values[1];
When I open pop-up, if text length is more than screen size, he need to show scroll bar.
sv.TextWrapping = TextWrapping.Wrap;
is possible or something another way?
All items ( scroll viewer, text ) I puts behind view, not in xaml (view) because my content are dynamic.
For you to be able to scroll anything inside a scrollviewer, you have to stop the scrollviewer from growing with the child element.
If this happens dynamically, give the scrollviewer a certain height and the text inside it will be scrollable
Create a TextBlock, assign the text to this TextBlock and add this TextBlock as the content of the ScrollViewer
var sv = new ScrollViewer();
var tb = new TextBlock
{
Text = //your text,
TextWrapping = TextWrapping.Wrap
}
sv.Content = tb;
Related
I have a Control that ultimately inherits from TextBox
If I don't remove the border then the text vertical alignment is fine:
But I want to remove the border like this:
public partial class MyReadonlyDataField : TextBox
{
private void InitializeComponent()
{
this.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent;
this.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.Height = 19;
}
}
But then the text alignment is off. How can I fix that?
I solved it. If I set the perfect height for my TextBox control then the text will be centered, because the control has the exact height that matches the text font.
To achieve that I set the hidden AutoSize property of TextBox. It can't be set in the Forms-Designer nor does IntelliSense list it as property. But it exists and works when set to true!
I am adding image to the radtreeviewitem from resources programatically using the below code.
"/myAssembley;component/Resources/image1.png"
and the image is displaying successfully. Now i need to add another image which needs to be displayed next to the first image in the radtreeviewitem.
how to achieve it.?
Like the below image i need my treeviewitem to display a folder icon and a red square icon in a single treeview item.
If you do not have data binding and you are using RadTreeViewItems directly you can add the additional image in the Header of the item. For example:
var stackPanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
var image1 = new Image() { Source = image1Path };
var image2 = new Image() { Source = image2Path };
var textBlock = new TextBlock() { Text = itemHeader };
stackPanel.Children.Add(image1);
stackPanel.Children.Add(image2);
stackPanel.Children.Add(textBlock);
var treeViewItem = new RadTreeViewItem()
{
Header = stackPanel,
};
It Works.
The proper way would be to create a DataTemplate with a grid or horizontal stackpanel. Put two images inside and in your model two Image Sources that you can bind too. Telerik doesn't have the best track record using the MVVM pattern, but the TreeView control is pretty decent with binding. If you need help with the model and the datatemplate, post some of your code here and we can work on it.
I try to add an scroll Viewer for a text block who was created from behind c#, text block was added to a stack panel stackPanel.Children.Add(text block). I want to do that in Windows Phone 8.0.
When make something like that:
StackPanel stackPanel = new StackPanel();
ScrollViewer sv = new ScrollViewer();
sv.Content = stackPanel;
I receive:
ExceptionObject = {"Value does not fall within the expected range."}.
One solution to solve that exception?
ScrollViewer calculates it's scrollbars based on dimensions of child controls.
If your TextBlock has Height property set, remove it and ScrollBars should work as expected.
Also you should set:
sv.Content = yourTextBlock;
With the following code (where Content is Grid):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var textBlock = new TextBlock() { Text = "hello" };
var stackPanel = new StackPanel();
stackPanel.Children.Add(textBlock);
var sv = new ScrollViewer { Content = stackPanel };
this.Content.Children.Add(sv);
}
I get the desired output:
So I tried to reproduce your error. I get the same exception if TextBlock is null. So maybe your code which creates the TextBlock has some issues? Here's an example:
TextBlock text = null;
var stackPanel = new StackPanel();
stackPanel.Children.Add(text);
var sv = new ScrollViewer { Content = stackPanel };
this.Content.Children.Add(sv);
Will result in:
In this tutorial a nice example of a TreeView is shown.
Now I would like to have two elements stacked with a StackPanel within a TreeViewItem vertically:
var treeViewItem = new TreeViewItem();
var stackPanel = new StackPanel() { Orientation = Orientation.Vertical };
stackPanel.Children.Add(... some text ...);
stackPanel.Children.Add(... some icon ...);
treeViewItem.Header = stackPanel;
The little arrow besides the TreeViewItem (to display its subitems) is now placed in the middle - between the icon and the text.
Question: Is it possible to adjust the arrow to the top (besides the icon)?
How do I add padding, or some space between the textboxes when using dockstyle.top property?
for(int i =0; i< 10; i++) {
textboxes[i] = new TextBox();
textboxes[i].Dock = DockStyle.Top;
mypanel.Controls.Add(textboxes[i]);
}
The code above puts textboxes right beneath each other. Can't figure this out without using mass panels or fixed positioning. How to do the following?
1) I would like to add around 10-20pixels between boxes.
2) How to change size (height,width) of the textboxes, since when using dockstyle.top it ignores the size commands ?
With DockStype.Top you can't change the width of your TextBoxes, cause they are docked. You can only change the height. But to change the height of a TextBox you have to set the Multiline = true beforehand.
To get the space between the different boxes you have to put each TextBox within a panel, set the TextBox.Dock = Fill, the Panel.Dock = Top and the Panel.Padding = 10. Now you have some space between each TextBox.
Sample Code
for (int i = 0; i < 10; i++)
{
var panelTextBox = CreateBorderedTextBox();
this.Controls.Add(panelTextBox);
}
private Panel CreateBorderedTextBox()
{
var panel = CreatePanel();
var textBox = CreateTextBox();
panel.Controls.Add(textBox);
return panel;
}
private Panel CreatePanel()
{
var panel = new Panel();
panel.Dock = DockStyle.Top;
panel.Padding = new Padding(5);
return panel;
}
private TextBox CreateTextBox()
{
var textBox = new TextBox();
textBox.Multiline = true;
textBox.Dock = DockStyle.Fill;
return textBox;
}
What i forgot, you can also give a try to the FlowLayoutPanel. Just remove the DockStyle.Top from the panels and put them into the FlowLayoutPanel. Also you should set the FlowDirection to TopDown. Maybe this can also help you to solve your problem, too.
Another work around that suits smaller layouts is to just add a Label control afterwards also docked to the Top, which is not AutoSized, Text=" ", Height=your padding. This is quite useful for the odd bit of padding when using the designer.
I know where you're coming from, this is especially frustrating after returning to WinForms from WPF.
I would suggest using a TableLayoutPanel, in which each TextBox would get its own cell, and adjusting the properties of the cells. This should solve both your padding and size problems.
Another alternative would be to use some more complex layout controls, such as the DevExpress ones (not free).