Could someone tell me how I can save all selected items in a xaml listbox in Powershell? I can one selected item, but not all selected items when the listbox selectionmode is set to "extended"?
<ListBox Name="ListBoxRelations" Margin="1,53,0,174" FontSize="11" SelectionMode="Extended" HorizontalAlignment="Left" Width="417"/>
After
$xaml.SelectNodes("//*[#Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$WMFStruct.SelectedHosts = $ListBoxRelations.SelectedItem
The above line only gets the first selected item in the listbox.
You are only getting a single item with the call to $ListBoxRelations.SelectedItem. You need to get the $ListBoxRelations.SelectedItems.
Then you can loop over the items.
Related
I have a nested gridview. There seems to be a problem with the Visibility. In the code below, OuterCollection and InnerCollection have HideInUI property which I inverse to determine the visibility (ex. if true, hide).
However, on the 2nd HideInUI, if the 1st item is hidden, it seems to hide everything else.
<GridView x:Name="GridView_Outer"
InnerCollectionsSource="{Binding Path=OuterCollection}">
<GridView.InnerCollectionTemplate>
<DataTemplate>
<StackPanel Visibility="{Binding Path=HideInUI, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<Button Content="{Binding Path=Title}"
IsEnabled="False"
Style="{StaticResource CategoryButton}"/>
<GridView x:Name="GridView_Inner"
InnerCollectionsSource="{Binding Path=InnerCollection}">
<GridView.InnerCollectionTemplate>
<DataTemplate>
<Button Width="120"
Command="{Binding ElementName=GridView_Outer, Path=DataContext.SelectPaymentTypeCommand}"
CommandParameter="{Binding Path=PaymentAmountTypeID}"
Content="{Binding Path=ScreenTitle}"
Visibility="{Binding Path=HideInUI, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
</Button>
</DataTemplate>
Edit
Sorry for the confusion. But what happens is.
Ex. Category 1 has Item 1, Item 2, Item 3. If HideInUI is true in Item1, Item2 and Item3 becomes hidden also. But if Item 2 or Item3 is HideInUI instead, it works properly. I can't seem to find out why.
The issue you have here is that you are setting the visibility of the StackPanel(in your outer gridview) that contains the rest of your solution. You have to look at it as boxes, everything within it is affected by its parents in some ways.
The tabulation is a great way to help you understand which block contains what, in your example, you can clearly see that your GridView contains one thing, which is a DataTemplate. This DataTemplate also contains one thing which is the StackPanel, and so on. In your case, your StackPanel contains everything else, so if you hide it, you hide everything in it also.
What I think you actually want, it is to hide the button in the "Outer GridView", in this case, you should set visibility of the "Title" button instead of setting the visibility of the whole StackPanel.
Cutting and pasting your code:
Visibility="{Binding Path=HideInUI, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
from your StackPanel to your "Title" button should do the trick.
I have a Windows Store XAML app with a "Save" button, which points to an ICommand property in my ViewModel.
<Button Content="Save"
Command="{Binding DataContext.SaveNewNote, ElementName=grid, Mode=OneWay}"
CommandParameter="{Binding DataContext.CurrentItem, ElementName=grid}" />
on the propertychanged event of my Note model, that fires the CanExecutedChanged event - every time (every keystroke). However, this button will only enable/disable once I leave focus of one of the related textboxes.
In other words, there is a "Name" textbox. If String.IsNullOrWhiteSpace(Name.Text), then CanExecute is set to false. This seems to execute with every keystroke.
I would expect to see this bound Save button enable and disable with each keystroke. HOWEVER, instead, I see the button enable/disable only when I tab out of the textbox.
How can I get this bound button to respect the CanExecuteChanged event on every keystroke, instead of when the texbox loses focus?
The comments by #will and #patrick on the original post both had the correct answer. To do this, you must set the "UpdateSourceTrigger" to "PropertyChanged" and that gives the intended results.
<TextBox Grid.Row="1" PlaceholderText="Enter a short description here"
Text="{Binding NoteAbstract, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
</TextBox>
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");
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>
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}}}"
/>