I am dynamically adding a button in Telerik RadListView. But the buttons are not wrapping the text.
Here is my code:
this.radBtnProduct = new RadButtonElement();
this.radBtnProduct.TextElement.Size = new Size(100,60); // .TextWrap = true;
this.radBtnProduct.Location = new Point(0, 0);
this.radBtnProduct.MinSize = new Size(100, 60);
this.radBtnProduct.MinSize = new Size(100, 60);
// wrapping
this.radBtnProduct.TextWrap = true;
Any help is appreciated
EDIT:
I used this code
this.radBtnProduct.Text = this.dataItem.Text.Replace(" ", "\n");
But am not sure if there are some issues with it
By default RadButtonElement has its AutoSize turned on. You need to switch it off in order to make your size work. Try this:
this.radBtnProduct = new RadButtonElement();
this.radBtnProduct.AutoSize = false;
this.radBtnProduct.Size = new Size(100, 60); // .TextWrap = true;
this.radBtnProduct.TextWrap = true;
Related
When I resize the following form with the right resize handle, the contained TableLayoutPanel gets decorated with scroll bars (as intended, panel1.AutoScroll = true) for smaller form sizes, but the TableLayoutPanel also gets displaced from its original position. See images below: after resizing the form with right resize handle only, the second one has its scroll bars not leftmost and the left border of the content is cut off.
It seems somehow that this behavior is tied to the existence of the nested RadioButtons because if I remove them (or replace them by another TextBox for example), the "normal" behavior is restored (TableLayoutPanel stays in place during resize).
What properties do I have to set in order to keep the content always stationary relative to the (top)left borders?
BTW: When I replace the panel1 by a TabControl + one TabPage, the "normal" behavior is also restored.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Test
{
/// <summary>
/// Description of Form3.
/// </summary>
public partial class Form3 : Form
{
const int textBoxNameWidth = 500;
TableLayoutPanel testControl1;
Panel panel1;
TextBox textBoxName;
RadioButton radioButtonNo;
RadioButton radioButtonYes;
TableLayoutPanel tableLayoutPanelDecision;
public Form3()
{
testControl1 = new TableLayoutPanel();
panel1 = new Panel();
textBoxName = new TextBox();
radioButtonNo = new RadioButton();
radioButtonYes = new RadioButton();
tableLayoutPanelDecision = new TableLayoutPanel();
testControl1.AutoSize = true;
testControl1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
testControl1.Location = new Point(0, 0);
testControl1.Dock = DockStyle.None;
testControl1.ColumnCount = 2;
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.RowCount = 2;
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.Controls.Add(textBoxName, 1, 0);
testControl1.Controls.Add(tableLayoutPanelDecision, 1, 1);
textBoxName.Text = "New Boolean";
textBoxName.TextAlign = HorizontalAlignment.Center;
textBoxName.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
textBoxName.TabStop = false;
textBoxName.Width = textBoxNameWidth;
tableLayoutPanelDecision.AutoSize = true;
tableLayoutPanelDecision.ColumnCount = 2;
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.RowCount = 1;
tableLayoutPanelDecision.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanelDecision.Controls.Add(radioButtonYes, 0, 0);
tableLayoutPanelDecision.Controls.Add(radioButtonNo, 1, 0);
tableLayoutPanelDecision.Dock = DockStyle.Fill;
radioButtonNo.Checked = true;
radioButtonNo.AutoSize = true;
radioButtonNo.TabIndex = 1;
radioButtonNo.TabStop = true;
radioButtonNo.Text = "False";
radioButtonNo.UseVisualStyleBackColor = true;
radioButtonNo.Anchor = AnchorStyles.None;
radioButtonYes.AutoSize = true;
radioButtonYes.TabIndex = 0;
radioButtonYes.Text = "True";
radioButtonYes.UseVisualStyleBackColor = true;
radioButtonYes.Anchor = AnchorStyles.None;
panel1.AutoScroll = true;
panel1.Controls.Add(testControl1);
panel1.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Location = new System.Drawing.Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new System.Drawing.Size(560, 219);
panel1.TabIndex = 1;
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(560, 219);
Controls.Add(panel1);
Name = "Form3";
Text = "Form3";
}
}
}
The panel is trying to keep focusable controls within view for the user. To change that, you would have to use your own panel:
public class PanelEx : Panel {
protected override Point ScrollToControl(Control activeControl) {
return this.DisplayRectangle.Location;
}
}
It seems not all bindings are to evaluated when printing. For example, in the code below, only the first button has content = "100", other buttons have content = "0".
var doc = new XpsDocument("test.xps",FileAccess.Write);
var writer = XpsDocument.CreateXpsDocumentWriter(doc);
var collator = writer.CreateVisualsCollator();
collator.BeginBatchWrite();
for (int i = 0; i < 3; i++)
{
var button = new Button();
button.SetBinding(ContentControl.ContentProperty,
new Binding
{
RelativeSource = new RelativeSource(RelativeSourceMode.Self),
Path = new PropertyPath("ActualWidth")
});
button.Measure(new Size(100, 100));
button.Arrange(new Rect(0, 0, 100, 100));
button.Width = 100;
button.Height = 100;
collator.Write(button);
}
collator.EndBatchWrite();
doc.Close();
Is there a workaround?
For example, is there a way to force the binding to evaluate?
Have you tried making sure the dispatcher is idle before the call to collator.EndBatchWrite().
Something like:
Dispatcher.CurrentDispatcher.Invoke(
new Action( delegate { } ), DispatcherPriority.ApplicationIdle, null );
VariableBox = gcnew ListView();
VariableBox->Font = ScriptEditorOptions->FontSelection->Font;
VariableBox->Dock = DockStyle::Fill;
VariableBox->BorderStyle = BorderStyle::Fixed3D;
VariableBox->BackColor = ScriptEditorOptions->BCDialog->Color;
VariableBox->ForeColor = ScriptEditorOptions->FCDialog->Color;
VariableBox->DoubleClick += gcnew EventHandler(this, &ScriptEditor::VariableBox_DoubleClick);
VariableBox->View = View::Details;
VariableBox->MultiSelect = false;
VariableBox->CheckBoxes = false;
VariableBox->FullRowSelect = true;
VariableBox->HideSelection = false;
VariableBox->Tag = (int)1;
ColumnHeader^ VariableBoxName = gcnew ColumnHeader();
VariableBoxName->Text = "Variable Name";
VariableBoxName->Width = 70;
ColumnHeader^ VariableBoxType = gcnew ColumnHeader();
VariableBoxType->Text = "Type";
VariableBoxType->Width = 50;
ColumnHeader^ VariableBoxIndex = gcnew ColumnHeader();
VariableBoxIndex->Text = "Index";
VariableBoxIndex->Width = 50;
VariableBox->Columns->Add(VariableBoxName);
VariableBox->Columns->Add(VariableBoxType);
VariableBox->Columns->Add(VariableBoxIndex);
VariableBox->ColumnClick += gcnew ColumnClickEventHandler(this, &ScriptEditor::VariableBox_ColumnClick);
I have the above code in a WinForms application. The control is added to the main form directly. For some reason, it never renders any items or columns when the layout is set to Details - Only the scroll bars are visible. The following code is used to add items to its collection:
ListViewItem^ Item = gcnew ListViewItem("Qw");
Item->SubItems->Add("Int");
Item->SubItems->Add("10");
VariableBox->Items->Add(Item);
Switching to any other view (at either run-time or design-time) fixes the issue. Any ideas on why this is happening ?
EDIT: Bump! Or is that not allowed ?
Turns out that I was removing the column headers before the control was displayed.
In WPF, I get a tooltip to appear immediately like this:
TextBlock tb = new TextBlock();
tb.Text = name;
ToolTip tt = new ToolTip();
tt.Content = "This is some info on " + name + ".";
tb.ToolTip = tt;
tt.Cursor = Cursors.Help;
ToolTipService.SetInitialShowDelay(tb, 0);
This makes the user experience better since if the user wants to look at the tooltips of five items on the page, he doesn't have to wait that long second for each one.
But since Silverlight does not have SetInitialShowDelay, what is a workaround to make the tooltip appear immediately?
You'll need to hook the MouseEnter event and show it straight away yourself:-
TextBlock tb = new TextBlock();
tb.Text = name;
ToolTip tt = new ToolTip();
tt.Content = "This is some info on " + name + ".";
ToolTipService.SetToolTip(tb, tt);
tb.MouseEnter += (s, args) => {
((ToolTip)ToolTipService.GetToolTip((DependencyObject)s)).IsOpen = true;
};
Other than re-implementing the mouse enter (or the whole tooltip service), I'm afraid you might be out of luck - the delay you see is actually hard-coded into the "OnOwnerMouseEnter" method of the TooltipService:
(courtesy of Reflector)
TimeSpan span = (TimeSpan) (DateTime.Now - _lastToolTipOpenedTime);
if (TimeSpan.Compare(span, new TimeSpan(0, 0, 0, 0, 100)) <= 0)
{
OpenAutomaticToolTip(null, EventArgs.Empty);
}
else
{
if (_openTimer == null)
{
_openTimer = new DispatcherTimer();
_openTimer.Tick += new EventHandler(ToolTipService.OpenAutomaticToolTip);
}
_openTimer.Interval = new TimeSpan(0, 0, 0, 0, 400);
_openTimer.Start();
}
I'm trying to fade in a new control to my application's "app" area which is programmatically added after the existing controls are removed. My code looks like this:
void settingsButton_Clicked(object sender, EventArgs e)
{
ContentCanvas.Children.Clear();
// Fade in settings panel
NameScope.SetNameScope(this, new NameScope());
SettingsPane s = new SettingsPane();
s.Name = "settingsPane";
this.RegisterName(s.Name, s);
this.Resources.Add(s.Name, s);
Storyboard sb = new Storyboard();
DoubleAnimation settingsFade = new DoubleAnimation();
settingsFade.From = 0;
settingsFade.To = 1;
settingsFade.Duration = new Duration(TimeSpan.FromSeconds(0.33));
settingsFade.RepeatBehavior = new RepeatBehavior(1);
Storyboard.SetTargetName(settingsFade, s.Name);
Storyboard.SetTargetProperty(settingsFade, new PropertyPath(UserControl.OpacityProperty));
ContentCanvas.Children.Add(s);
sb.Children.Add(settingsFade);
sb.Begin();
}
However, when I run this code, I get the error "No applicable name scope exists to resolve the name 'settingsPane'."
What am I possibly doing wrong? I'm pretty sure I've registered everything properly :(
I wouldn't hassle with the NameScopes etc. and would rather use Storyboard.SetTarget instead.
var b = new Button() { Content = "abcd" };
stack.Children.Add(b);
var fade = new DoubleAnimation()
{
From = 0,
To = 1,
Duration = TimeSpan.FromSeconds(5),
};
Storyboard.SetTarget(fade, b);
Storyboard.SetTargetProperty(fade, new PropertyPath(Button.OpacityProperty));
var sb = new Storyboard();
sb.Children.Add(fade);
sb.Begin();
I solved the problem using this as parameter in the begin method, try:
sb.Begin(this);
Because the name is registered in the window.
I agree, the namescopes are probably the wrong thing to use for this scenario. Much simpler and easier to use SetTarget rather than SetTargetName.
In case it helps anyone else, here's what I used to highlight a particular cell in a table with a highlight that decays to nothing. It's a little like the StackOverflow highlight when you add a new answer.
TableCell cell = table.RowGroups[0].Rows[row].Cells[col];
// The cell contains just one paragraph; it is the first block
Paragraph p = (Paragraph)cell.Blocks.FirstBlock;
// Animate the paragraph: fade the background from Yellow to White,
// once, through a span of 6 seconds.
SolidColorBrush brush = new SolidColorBrush(Colors.Yellow);
p.Background = brush;
ColorAnimation ca1 = new ColorAnimation()
{
From = Colors.Yellow,
To = Colors.White,
Duration = new Duration(TimeSpan.FromSeconds(6.0)),
RepeatBehavior = new RepeatBehavior(1),
AutoReverse = false,
};
brush.BeginAnimation(SolidColorBrush.ColorProperty, ca1);
It is possible odd thing but my solution is to use both methods:
Storyboard.SetTargetName(DA, myObjectName);
Storyboard.SetTarget(DA, myRect);
sb.Begin(this);
In this case there is no error.
Have a look at the code where I have used it.
int n = 0;
bool isWorking;
Storyboard sb;
string myObjectName;
UIElement myElement;
int idx = 0;
void timer_Tick(object sender, EventArgs e)
{
if (isWorking == false)
{
isWorking = true;
try
{
myElement = stackObj.Children[idx];
var possibleIDX = idx + 1;
if (possibleIDX == stackObj.Children.Count)
idx = 0;
else
idx++;
var myRect = (Rectangle)myElement;
// Debug.WriteLine("TICK: " + myRect.Name);
var dur = TimeSpan.FromMilliseconds(2000);
var f = CreateVisibility(dur, myElement, false);
sb.Children.Add(f);
Duration d = TimeSpan.FromSeconds(2);
DoubleAnimation DA = new DoubleAnimation() { From = 1, To = 0, Duration = d };
sb.Children.Add(DA);
myObjectName = myRect.Name;
Storyboard.SetTargetName(DA, myObjectName);
Storyboard.SetTarget(DA, myRect);
Storyboard.SetTargetProperty(DA, new PropertyPath("Opacity"));
sb.Begin(this);
n++;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message + " " + DateTime.Now.TimeOfDay);
}
isWorking = false;
}
}