I would like to fill my ListView with do aligned elements, a little icon (either a confirm mark or a cross) and a string which contains the result of a question (Right / Wrong, that's why icon).
daInserire = new ListViewItem();
daInserire.Foreground = new SolidColorBrush(Colors.DarkGreen);
daInserire.Content = "Giusto: "+ straniero.Text + " = " + vocItaliano[current];
daInserire.HorizontalContentAlignment = HorizontalAlignment.Center;
daInserire.FontSize = 18;
//...
listViewConInfo.Items.Add(daInserire);
This works perfectly, I'd like to add before the string, on the same line an image.
Looks like you're using WPF, so you'll need to create a StackPanel for your Content property and add the Image and a Label to that StackPanel.
ListView lV = new listView();
ListViewItem Item = new ListViewItem();
WrapPanel wrap = new WrapPanel();
Image image = new image();
image.Source = <<yourSource>>;
Label label = new Label();
label.Content = "W/E you want";
wrap.Children.Add(image);
wrap.Children.Add(label);
Item.Content = wrap;
lV.Items.Add(Item);
Related
I create a label and set his TEXT color to red. I use ForeColor property but with him not working :(
This is my UI:
This is my label code:
Label reqF = new Label();
reqF.Text = "*";
reqF.ForeColor = System.Drawing.Color.Red;
reqF.CssClass = "formvalidation";
reqF.Font.Size = 15; // 15px
This is my string code:
TableHeaderCell header1 = new TableHeaderCell();
header1.Text = "Destination" + reqF.Text; <----------- My label
tRow0.Cells.Add(header1);
In this line
header1.Text = "Destination" + reqF.Text;
you add only the text (*) to the destination, not the full div with the style on.
The easiest (and faster) way is to direct add the style online as:
header1.Text = "Destination <span style=\"color=red\">*</span>" ;
You are only using text of the control, not the whole control with styling. Your code should actually look something like that:
TableHeaderCell header1 = new TableHeaderCell();
LiteralControl literal = new LiteralControl();
literal.Text = "Destination";
header1.Controls.Add(literal);
header1.Controls.Add(reqF);
tRow0.Cells.Add(header1);
Note that here Literal control is used to insert the Description string, and then the whole Label with the * is being inserted.
The code below generates a treeview node with an Icon (from a .PNG file Piconfolder\PiconName) followed by a Text string Pheader.
I want to add a background to just the icon (to be used with transparent icons)
public static TreeViewItem CreateTreeViewItem(
string Pheader,
string PiconFolder,
string PiconName)
{
string iconFolder = PiconFolder;
string iconName = PiconName;
string header = Pheader;
TreeViewItem child = new TreeViewItem();
StackPanel pan = new StackPanel();
pan.Orientation = Orientation.Horizontal;
string fPath = System.IO.Path.Combine(iconFolder, iconName);
Image image = new Image();
image.Height = 16;
image.Width = 16;
image.Source = new BitmapImage(new Uri(fPath, uriKind.RelativeOrAbsolute));
pan.Children.Add(image);
pan.Children.Add(new TextBlock(new Run(" " + header)));
child.Header = pan;
}
Replace
pan.Children.Add(image);
with
var iconPanel = new Grid(); // or other panel
iconPanel.Background = Brushes.Blue;
iconPanel.Children.Add(image);
pan.Children.Add(iconPanel);
I wanted to display no of course json objects in each textbox
but as they are unpredictable number of objects therefore i created textbox on the fly using this code
List<Course> Cdata = JsonConvert.DeserializeObject<List<Course>>(App.data);
TextBox[] Tblock = new TextBox[Cdata.Count];
double top = 0; int i = 0;
foreach (Course de in Cdata)
{
result += de.course_name + "\r\n";
result += "Total Absents = " + de.absents;
result += " + " + de.presents;
result += " = " + de.sessions + "\r\n\r\n\r\n";
Tblock[i] = new TextBox();
Tblock[i].Text = result;
Tblock[i].AcceptsReturn = true;
Tblock[i].TextWrapping = TextWrapping.Wrap;
Tblock[i].Width = 475;
Tblock[i].Height = 270;
Tblock[i].IsReadOnly = true;
Tblock[i].Margin =new Thickness (0,top,0,0);
Tblock[i].Visibility = System.Windows.Visibility.Visible;
Tblock[i].VerticalAlignment = System.Windows.VerticalAlignment.Top;
top += 270; i++;
result = "";
}
Now when i debug my app data it is working as its supposed to the only problem is textbox
never display on View
and i haven't coded any textbox in Xaml file of view
Thanks in Advance
You have to add the Textboxes to any existing Panel (generally to Grid or StackPanel) in the XAML as shown below
StackPanel sp = new StackPanel(); //Create stack panel before foreach loop
foreach (Course de in Cdata)
{
//your code which you shown above
sp.Children.Add(Tblock[i]); //Add all the Textboxes to the stackpanel
}
ContentPanel.Children.Add(sp); //And add the above stackpanel to the existing Grid named ContentPanel
By the way, I suggest you to use a ListBox with ItemTemplate to bind the data instead of creating the TextBoxes as shown above.
Also, I don't understand why you have choosen TextBox instead of TextBlock to display data
I am trying to add multiple items in to a grid, so that later items will pop up underneath earlier items.
TextBox foo = new TextBox();
foo.Text = " " + id + " ";
foo.Width = 440;
foo.Height = 200;
foo.VerticalAlignment = "Top";
foo.Background = new SolidColorBrush(Colors.Red);
((Grid)daysPanels[id].Content).Children.Add(foo);
Unfortunately, the VerticalAlignment = "Top" line isn't working, it says it can't implicitly convert type "String" to type "VerticalAlignment". Am I doing this the right way and how can I fix that error?
Look at the msdn documentation. VerticalAlignment is an enum.
foo.VerticalAlignment = VerticalAlignment.Top;
I am creaing a table cell, and in in, I want an image, and UNDER the image, a description. So, I attempted this:
TableCell cell = new TableCell();
ImageButton i = new ImageButton
{
ImageUrl = image.fullThumbPath,
PostBackUrl =
"~/fulldisplay.aspx?imageId=" + image.visibleId + #"&r=" +
GlobalVariables.RandomString(5)
};
cell.Controls.Add(i);
Label l = new Label
{
Text = image.description
};
l.Style.Add("font-weight", "bold");
cell.Controls.Add(l);
row.Cells.Add(cell);
However, what I end up with is the image, and NEXT to the image, a label. How would I ensure the label is under the image? I can't add a .
See if changing your code as below works for you.
Label l = new Label
{
Text = "<br>" + image.description
};
I have added a br tag before the image description so that the image description will come in next line.