I have a ListbBox that contains grid items. Inside grids are TextBlocks. How can I resolve the textblock.Text of each listbox item?
I think that listbox.Items[index-1] returns an object but I can't get the textblock value.
I create dynamically
Grid g = new Grid();
g.Background = new SolidColorBrush(Colors.Brown);
And then
TextBlock txt = new TextBlock();
txt.Text = "some dynamically text";
And
g.Children.Add(txt);
listbox.Items.Add(g);
where listbox is my ListBox
When I load some values I want to resolve the text
int epilogi = listbox.SelectedIndex;
listbox.Items.RemoveAt(epilogi);
object tempkati = listbox.Items[epilogi-1];
I want the text from the tempkati object
Try this:
var grid = listbox.Items[epilogi - 1] as Grid;
var textblock = grid.Children[0] as TextBlock;
var text = textblock.Text;
Related
I am using openlayers 3. From the values contained in a vector GeoJSON, I want to fill a dropdown menu. When selecting a value from the dropdown menu, I want to zoom in on the entity.
My problem now is that I want to generate my HTML from the attributes of my GeoJSON. So I tried this simple code but it doesn't work :
var menu = document.getElementById('menuDropDown');
vector2.getSource().forEachFeature(function() {
menu.innerHTML = feature.get('NOM').join(', ');
});
EDIT:
I'm able to populate a dropdown menu from a list:
var list = ['a','b','c'];
var mySelect = $('#mySelect');
$.each(list, function(val, text) {
mySelect.append(
$('<option></option>').val(val).html(text)
);
});
What i want to do it's to populate this list from the attribute of my vector
So i try this:
// vector2 it's a GeoJSON who is integrate on my map
vector2.getSource().getFeatures().forEachFeature(function(feature) {
list.push(feature.get('NOM'));
});
Firstly I'm assuming you have to pass some parameter to your callback:
vector2.getSource().forEachFeature(function(feature) {
Then you can append an item to a dropdown like so:
var item = document.createElement('option');
item.setAttribute('value', feature.get('NOM'));
var textNode = document.createTextNode(feature.get('NOM'));
item.appendChild(textNode)
menu.appendChild(item);
All together:
var menu = document.getElementById('menuDropDown');
vector2.getSource().forEachFeature(function(feature) {
var item = document.createElement('option');
item.setAttribute('value', feature.get('NOM'));
var textNode = document.createTextNode(feature.get('NOM'));
item.appendChild(textNode)
menu.appendChild(item);
});
I have resolve my problem:
vector2.getSource().on('change', function(evt){
var source = evt.target;
var list = [];
source.forEachFeature(function(feature) {
list.push(feature.get('NOM'));
});
// console.log("Ecrit moi les noms : " + list);
Thanks you to those who took the time to respond
I am handling the change event of the kendo ui grid.
In the event handler, I would like to get the cell that was clicked that invoked the change event. I need the cell in order to scan its contents.
Any thoughts?
It's actually very well documented in the documentation: http://docs.telerik.com/kendo-ui/api/web/grid#events-change
Here's the example code if you have the grid configured for multiple cell selection (selectable: "multiple, cell"):
change: function(e) {
var item;
var selected = this.select(); //get selected cell(s)
for (var i = 0; i < selected.length; i++) {
item = this.dataItem(selected[i].parentNode); //get selected cell's dataItem
}
}
In order to select the table cell that was clicked to edit, simply use e.container. There are a number of options given from the event handler. Here's a few:
change: function (e) {
//jQuery object containing the cell
var cell = e.container;
//jQuery object containing the input
var field = cell.find("input");
//value in the input
var fieldVal = field.val();
//or, on one line:
fieldVal = e.container.find("input").val();
//also, if you happen to want the data model for that row
var model = e.model;
}
I've been doing a essay about map on windows phone. I added pushpins default into map and its content is a image. I want to show information when I tap or click on pushpin, but I don't know what to do. I've just thought about use tooltip to show info, but I can't do it.
here is my createpushpin function.
can you help me? thank you for all kind of you!
private void CreateNewPushpin(object selectedItem)
{
var pushpinPrototype = selectedItem as Pushpinsmodel;
var pushpinicon = pushpinPrototype.Icon;
Pushpin pushpins = new Pushpin() { Tag = adress.Name };
pushpins.Background = new SolidColorBrush(Colors.Green);
pushpins.Location = new GeoCoordinate(lad, long);
ImageBrush image = new ImageBrush() {
ImageSource = new System.Windows.Media.Imaging.BitmapImage
(pushpinicon)};
Ellipse elip = new Ellipse()
{
Fill = image,
Name = adress.Name,
StrokeThickness = 10,
Height = 30,
Width = 30
};
pushpins.Content = elip;
var tooltipText = new ToolTip { Content = adress.Name};
ToolTipService.SetToolTip(pushpins, tooltipText);
map1.Children.Add(pushpins);
listpushpin.Add(pushpins);
this.map1.SetView(pushpins.Location, 18.0);
}
I am creating a hyperlink button like this:
HyperlinkButton hlbMail = new HyperlinkButton();
hlbMail.Height = 89;
hlbMail.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
hlbMail.VerticalAlignment = System.Windows.VerticalAlignment.Top;
hlbMail.Margin = new Thickness(60, -70, 0, 0);
hlbMail.Width = 290;
hlbMail.FontSize = 22;
TextBlock btnContent = new TextBlock();
btnContent.TextWrapping = TextWrapping.Wrap;
btnContent.Text = message;
btnContent.Visibility = System.Windows.Visibility.Visible;
hlbMail.Content = btnContent;
hlbMail.Visibility = System.Windows.Visibility.Visible;
mailStackPanel.Children.Add(hlbMail);
mailscrollViewer.Content = mailStackPanel;
PIMail.Content = mailscrollViewer;
But i have a problem in which the content of the button is not being displayed. As can be seen, the content is supposed to be the text of the TextBlock (the message var is a string which is not empty). What can be the reason that the content is not being shown?
You need to use this:
hlbMail.Content= btnContent.Text;
I think you forgot to add the .Text.
You cannot have a hyperlinkbutton having textblock as its content. But you can have the text of a textblock as the content of the hyperlink
As you also mentioned you need the text of textblock than you need to specify that you need the text by adding the btnContent.Text;
I'm loading elements on a page dynamically (reading the contents of an XML file). The dynamic content is loaded into a StackPanel. Each element of the content consists of a TextBlock and one other UI element, so for each pair I create a new StackPanel which is then added to the parent StackPanel. The code looks like this:
TextBlock header = new TextBlock() {
Text = "Heading 1",
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top,
Foreground = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"],
};
TextBox item = new TextBox() {
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top,
};
StackPanel sp = new StackPanel();
sp.Children.Add( header );
sp.Children.Add( item );
parentSP.Children.Add( sp );
I want to add a ContextMenu to this StackPanel (sp, not parentSP); depending on some parameters read from the file it could be one of 2 different context menus. I tried the following but it is not working:
ContextMenu cm = new ContextMenu();
RoutedEventHandler clickHandler = new RoutedEventHandler( OnContextMenuClicked );
// Add "edit" entry
MenuItem menuItem = new MenuItem() {
Header = "edit",
Tag = "edit",
};
menuItem.Click += clickHandler;
cm.Items.Add( menuItem );
// Add "delete" entry
menuItem = new MenuItem() {
Header = "delete",
Tag = "delete",
};
menuItem.Click += clickHandler;
cm.Items.Add( menuItem );
parentSP.Children.Add( cm );
How do I add a context menu to the StackPanel programmatically?
Also, is there a better way to solve this problem? Maybe by storing the 2 different types of context menus in a XAML resources section and adding them as needed? I tried doing this by adding the context menus to the parent's StackPanel.Resource section but got an error saying "A property element cannot be the direct child of another property element"
Thanks in advance for your help
ContextMenuService.SetContextMenu(sp, cm);