How to get listbox column text with xul - xul

I am new with xul,
I want to know how to get listbox column text with xul,
I search about listbox method and property, but I can't find about that
please help!
Thanks a lot!

You can see the reference page listbox - XUL
If you want to get the selected item, there is a property of the listbox called selectedItem that will return it.
Your listitem can be composed with multiple elements.
<listbox id="list">
<listitem class="listitem">
<listcell class="column1" value="value1" width="100"/>
<listcell class="column2" value="value2" width="100"/>
</listitem>
</listbox>
If you give this elements a class, you can access them doing the following:
var list = document.getElementById("list");
var listItem = list.selectedItem;
var column1Value = listItem.getElementsByClassName("column1")[0].getAttribute("value");
var column1Value = listItem.getElementsByClassName("column2")[0].getAttribute("value");

Related

Numbering a ListView

I have a ListView whose Data Context is an ObservableCollection. I then used XAML to format the items and bind to their properties in the ListView in ListView.ItemTemplate.DataTemplate . Now, I want to add a TextBlock here to display the position of the item in the ListView through Binding in XAML. How to do that?
If I got your question right, you just need to add a TextBlock in each item DataTemplate with the index number inside the ListView, right?
If so, you can easily do that by doing something like this:
<DataTemplate x:Key="ItemTemplate">
<Grid>
<!--All your various UI elements here...-->
<!--Add a TextBlock with the formatting you want-->
<TextBlock Text="{Binding Position}"/>
</Grid>
</DataTemplate>
And in C#, add something like this after you've created your Source ObservableCollection, before assigning it to the Property inside your ViewModel:
for (int i = 0; i < myCollection.Count; i++)
{
myCollection[i].Position = Convert.ToString(i);
}
//And then, the usual
Source = myCollection
NB: I'm assuming you have a Property called Source in your ViewModel with INotifyPropertyChanged implemented. You will also have to modify the class you use inside your ObservableCollection and add the Position property of course :)

Horizontal long list selector xaml

I have items coming from server dynamically and I need to create an ItemTemplate for those items.
I looked for ScrollViewer but I couldn't find ItemTemplate or ItemsSource property.
Is there a way to list items in phone:longListSelector horizontally?
You can inside your Scrollviewer use a Listbox like this;
<ScrollViewer>
<ListBox ItemsSource="your source" ItemTemplate="your template" />
</ScrollViewer>

Windows 8 - GridView does not return SelectedItem when a button inside an item is clicked

I am working on a Win8 Metro Application. I am using a GridView. In GridView's ItemTemplate, I have 3 buttons (Button1, Button2, Button3). So, on my screen, if I have 5 GridView Items at a time, then I will see 5x3 = 15 buttons.
The problem is that if any of these buttons is clicked, I am unable to trace parent GridView Item.
Amongst GridView's properties, "SelectedIndex" (or SelectedItem) properties are there. However, its value is set when GridView item is clicked, (not when a button inside GridViewItem is clicked). So, on clicking button, SelectedIndex remains -1.
How can I find out on ButtonClick that who is the parent item of this button?
From reading your replies in comments, it seems like you want to get the reference to the underlying data item rather than the grid item itself. That being the case, do the following in your button click handler...
Void Button_Click(sender, e)
{
var btn = (Button)sender;
var dc = btn.DataContext as MyBoundType; // don't forget to check for null!
var itemId = dc.Id; // assuming your object has an Id field
}
Bind the CommandParameter of the button to the parent item like this:
<Button
Command="{Binding RemoveCommand}"
CommandParameter="{Binding RelativeSource=
{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
/>

XAML button content changing based on VB variable

Beginner here. I want to create a button in XAML which has text based on a variable in VB. I have the variable set in VB with
Dim ButtonName1 = "Test"
What will I need to do to make the button content display ButtonName1?
It is really quite easy. Your Button has a Name Property that you can use to reference it in your code behind, note in this example it is Button1 you just need to assign your string to the Button's Content Property
Xaml
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
xaml.vb
Dim ButtonName1 = "Test"
Button1.Content = ButtonName1

Silverlight Find Control in Data Template

I have the following xaml code:
<dxb:BarButtonItem Name="btnPrev" Cursor="Hand" ItemClick="btnPrev_ItemClick">
<dxb:BarButtonItem.ContentTemplate>
<DataTemplate>
<Image x:Name="imgSkipLeft" Source="/ProjectTool;component/images/arrowleft.png" Height="16" Width="16">
<ToolTipService.ToolTip>
<TextBlock x:Name="txtBlockTip_Left"/>
</ToolTipService.ToolTip>
</Image>
</DataTemplate>
</dxb:BarButtonItem.ContentTemplate>
</dxb:BarButtonItem>
How can I find txtBlockTip_Left and modify the text
Rather that trying to find the TextBlock on the DataTemplate to change the text it would be better to set the text through a binding and then change the property that the Text property is bound to. The following resource has an example on how to use data binding within a DataTemplate: http://www.silverlight.net/learn/data-networking/binding/data-binding-to-controls-%28silverlight-quickstart%29
Using the VisualTreeHelperExtensions class and put a grid inside the data template and give it a name, in the example below the name is grdTemplate.
var bttn= btnPrev.ItemContainerGenerator.ContainerFromItem(btnPrev);
var dataTemplate = bttn.GetDescendantsOfType<Grid>().FirstOrDefault(g => g.Name == ("grdTemplate"));
var textBlocks= VisualTreeHelperExtensions.GetDescendantsOfType<TextBlock>(dataTemplate);
TextBlock txtBlockTip_left = textBlocks.ElementAt(0);