Search Results

Search found 919 results on 37 pages for 'listbox'.

Page 2/37 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • WPF: Exception if i add a eventhandler to a MenuItem (in a ListBox)

    - by user437899
    Hi, i wanted a contextmenu for my ListBoxItems. So i created this: <ListBox Name="listBoxName"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding UserName}" /> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="View" Name="MenuItemView" /> </ContextMenu> </Setter.Value> </Setter> </Style> </ListBox.ItemContainerStyle> </ListBox> This works great. I have the contextmenu for all items, but if i want to add a click-eventhandler to the menuitem, like this: <MenuItem Header="View" Name="MenuItemView" Click="MenuItemView_Click" /> I get a XamlParseException when the window is created. InnerException: The Object System.Windows.Controls.MenuItem cannot be converted to type System.Windows.Controls.Grid It throws only the exception if i add a event-handler. The event-method is empty.

    Read the article

  • ListBox Items Not Visible after DataBinding

    - by SidC
    Good Evening All, I am writing a page that allows users to search a parts table, select quantities and a listbox is to be populated with gridview values. Here's a snippet of my aspx page: <asp:ListBox runat="server" ID="lbItems" Width="155px"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:ListBox> Here's the relevant contents of codebehind: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Define DataTable Columns as incoming gridview fields Dim dtSelParts As DataTable = New DataTable Dim dr As DataRow = dtSelParts.NewRow() dtSelParts.Columns.Add("PartNumber") dtSelParts.Columns.Add("NSN") dtSelParts.Columns.Add("PartName") dtSelParts.Columns.Add("Qty") 'Select those gridview rows that have txtQty <> 0 For Each row As GridViewRow In MySearch.Rows Dim textboxText As String = _ CType(row.FindControl("txtQty"), TextBox).Text If textboxText <> "0" Then 'Create the row dr = dtSelParts.NewRow() 'Fill the row with data dr("PartNumber") = MySearch.DataKeys(row.RowIndex)("PartNumber") dr("NSN") = MySearch.DataKeys(row.RowIndex)("NSN") dr("PartName") = MySearch.DataKeys(row.RowIndex)("PartName") 'Add the row to the table dtSelParts.Rows.Add(dr) End If Next 'Need to send items to Listbox control lbItems lbItems.DataSource = New DataView(dtSelParts) lbItems.DataValueField = "PartNumber" lbItems.DataValueField = "NSN" lbItems.DataValueField = "PartName" lbItems.DataBind() End Sub The page runs fine in that my search functiobnality is intact, and I can input quantity values into my gridview's textbox. When I click Add to Quote the Listbox receives focus, but no list items are visible. I've created several list items in the aspx page, however I don't know how to populate the contents of my datatable in the listbox. Can someone help a newbie with this, seemingly, easy issue? Thanks, Sid

    Read the article

  • ListBox and Listview problem

    - by Anu
    Hi, I have listbox in my applcation and corresponding coding.. XAML: <DataTemplate x:Key="menuItemTemplate"> <WrapPanel> <TextBlock Text="{Binding Path = Menu}" /> </WrapPanel> </DataTemplate> <ListBox x:Name="menubox" ItemsSource="{Binding}" ItemTemplate="{StaticResource menuItemTemplate}" Margin="0,5,0,0"> .CS : public void Add(string[] menu) { ItemList items = ItemList.Load(menu); DataContext = items; } It works fine.Later i add Listview for another purpose and i coded like the same way of listbox XAML: <DataTemplate x:Key="ListItemTemplate"> <WrapPanel> <TextBlock Text="{Binding Path = Title}" /> </WrapPanel> </DataTemplate> <ListView ItemsSource="{Binding}" ItemTemplate="{StaticResource ListItemTemplate}" Name="listView1" /> .cs coding: public void SetTree(string Title,int BoxNo ) { TreeList items1 = TreeList.Load(Title,BoxNo); DataContext = items1; } After adding Listview,what happended this ListView show data,but Listbox didnot show anything.When i click the listbox it perfectly executing the clicking event of listbox.Only problem it doesnot display the text.What can i do for that. Here i added corresponding list class pls see tht. namespace Tabcontrol { public class TreeList : Collection<TreeItems> { public int size; public TreeList() { size = 0; } public int Count { get { return size; } } public static TreeList Load(string pmenu,int Box) { TreeList result = new TreeList(); TreeItems item = TreeItems.Load(pmenu,Box); result.Add(item); return result; } } } The ItemList class also the same thing, only variable names are getting differred.

    Read the article

  • Dynamically add columns to a listbox

    - by mgroves
    I'm brand new to Windows Phone 7 development, and almost as equally new to Silverlight. I have a ListBox with a DataTemplate, StackPanel, and TextBlocks like so: <ListBox Height="355" HorizontalAlignment="Left" Margin="6,291,0,0" Name="detailsList" VerticalAlignment="Top" Width="474" Background="#36FFFFFF"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Width="50" Text="{Binding Ticker}" /> <TextBlock Width="50" Text="{Binding Price}" /> <TextBlock Width="50" Text="{Binding GainLoss}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> I have some C# code to populate it: var info = new List<StockInfo>(); info.Add(new StockInfo { Ticker = "C", Price = "5.18", GainLoss = "10" }); info.Add(new StockInfo { Ticker = "WEN", Price = "4.18", GainLoss = "12" }); info.Add(new StockInfo { Ticker = "CBB", Price = "5.22", GainLoss = "210" }); detailsList.ItemsSource = info; And that all works fine. My question is: how do I add/remove additional 'textblocks' to the listbox dynamically (at runtime)? Also, how do I put column headers on the list box?

    Read the article

  • Bind listbox in WPF with grouping

    - by Michael Stoll
    Hi, I've got a collection of ViewModels and want to bind a ListBox to them. Doing some investigation I found this. So my ViewModel look like this (Pseudo Code) interface IItemViewModel { string DisplayName { get; } } class AViewModel : IItemViewModel { string DisplayName { return "foo"; } } class BViewModel : IItemViewModel { string DisplayName { return "foo"; } } class ParentViewModel { IEnumerable<IItemViewModel> Items { get { return new IItemViewModel[] { new AItemViewModel(), new BItemViewModel() } } } } class GroupViewModel { static readonly GroupViewModel GroupA = new GroupViewModel(0); static readonly GroupViewModel GroupB = new GroupViewModel(1); int GroupIndex; GroupViewModel(int groupIndex) { this.GroupIndex = groupIndex; } string DisplayName { get { return "This is group " + GroupIndex.ToString(); } } } class ItemGroupTypeConverter : IValueConverter { object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is AItemViewModel) return GroupViewModel.GroupA; else return GroupViewModel.GroupB; } } And this XAML <UserControl.Resources> <vm:ItemsGroupTypeConverter x:Key="ItemsGroupTypeConverter "/> <CollectionViewSource x:Key="GroupedItems" Source="{Binding Items}"> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription Converter="{StaticResource ItemsGroupTypeConverter }"/> </CollectionViewSource.GroupDescriptions> </CollectionViewSource> </UserControl.Resources> <ListBox ItemsSource="{Binding Source={StaticResource GroupedItems}}"> <ListBox.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayName}" FontWeight="bold" /> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListBox.GroupStyle> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayName}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> This works somehow, exept of the fact that the binding of the HeaderTemplate does not work. Anyhow I'd prefer omitting the TypeConverter and the CollectionViewSource. Isn't there a way to use a property of the ViewModel for Grouping? I know that in this sample scenario it would be easy to replace the GroupViewModel with a string an have it working, but that's not an option. So how can I bind the HeaderTemplate to the GroupViewModel?

    Read the article

  • ListBox item doesn't get refresh in WPF?

    - by sanjeev40084
    I have a listbox which has couple of items. When double clicked on each item, the user get option to edit item (text of item). Now once i update the item, my item in listbox doesn't get updated. The first window (one which has listbox) is in MainWindow.xaml file and second window is in EditTaskView.xaml(one which let's edit the items text) file. The code that displays items in lists is: Main.Windows.cs public static ObservableCollection TaskList; public void GetTask() { TaskList = new ObservableCollection<Task> { new Task("Task1"), new Task("Task2"), new Task("Task3"), new Task("Task4") }; lstBxTask.ItemsSource = TaskList; } private void lstBxTask_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var selectedTask = (Task)lstBxTask.SelectedItem; EditTask.txtBxEditedText.Text = selectedTask.Taskname; EditTask.PreviousTaskText = selectedTask.Taskname; EditTask.Visibility = Visibility.Visible; } The xaml code that displays the list: <ListBox x:Name="lstBxTask" Style="{StaticResource ListBoxItems}" MouseDoubleClick="lstBxTask_MouseDoubleClick"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Rectangle Style="{StaticResource LineBetweenListBox}"/> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Taskname}" Style="{StaticResource TextInListBox}"/> <Button Name="btnDelete" Style="{StaticResource DeleteButton}" Click="btnDelete_Click"/> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <ToDoTask:EditTaskView x:Name="EditTask" Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="2" Visibility="Collapsed"/> The Save button in TaskEditView.xaml does this: public string PreviousTaskText { get; set; } private void btnSaveEditedText_Click(object sender, RoutedEventArgs e) { foreach (var t in MainWindow.TaskList) { if (t.Taskname == PreviousTaskText) { t.Taskname = txtBxEditedText.Text; } } Visibility = Visibility.Collapsed; } TaskList is the ObservableCollection, and i though once you update the value the UI gets refreshed. But doesn't seem to work that way. What am i missing?

    Read the article

  • VBA-Sorting the data in a listbox, sort works but data in listbox not changed

    - by Mike Clemens
    A listbox is passed, the data placed in an array, the array is sort and then the data is placed back in the listbox. The part that does work is putting the data back in the listbox. Its like the listbox is being passed by value instead of by ref. Here's the sub that does the sort and the line of code that calls the sort sub. Private Sub SortListBox(ByRef LB As MSForms.ListBox) Dim First As Integer Dim Last As Integer Dim NumItems As Integer Dim i As Integer Dim j As Integer Dim Temp As String Dim TempArray() As Variant ReDim TempArray(LB.ListCount) First = LBound(TempArray) ' this works correctly Last = UBound(TempArray) - 1 ' this works correctly For i = First To Last TempArray(i) = LB.List(i) ' this works correctly Next i For i = First To Last For j = i + 1 To Last If TempArray(i) > TempArray(j) Then Temp = TempArray(j) TempArray(j) = TempArray(i) TempArray(i) = Temp End If Next j Next i ! data is now sorted LB.Clear ! this doesn't clear the items in the listbox For i = First To Last LB.AddItem TempArray(i) ! this doesn't work either Next i End Sub Private Sub InitializeForm() ' There's code here to put data in the list box Call SortListBox(FieldSelect.CompleteList) End Sub Thanks for your help.

    Read the article

  • MVVM - ListBox SelectedItem Binding Property Going Null

    - by Peanut
    So i have a listbox: <ListBox x:Name="listbox" HorizontalAlignment="Left" Margin="8,8,0,8" Width="272" BorderBrush="{x:Null}" Background="{x:Null}" Foreground="{x:Null}" ItemsSource="{Binding MenuItems}" ItemTemplate="{DynamicResource MenuItemsTemplate}" SelectionChanged="ListBox_SelectionChanged" SelectedItem="{Binding SelectedItem}"> </ListBox> and i have this included in my viewmodel: public ObservableCollection<MenuItem> MenuItems { get { return menuitems; } set { menuitems = value; NotifyPropertyChanged("MenuItems"); } } public MenuItem SelectedItem { get { return selecteditem; } set { selecteditem = value; NotifyPropertyChanged("SelectedItem"); } } and also in my viewmodel: public void UpdateStyle() { ActiveHighlight = SelectedItem.HighlightColor; ActiveShadow = SelectedItem.ShadowColor; } So, the objective is to call UpdateStyle() whenever selectedchanged event is fired. So in the .CS file, i call UpdateStyle(). The problem is, whenever I get into the selectionchanged event method, my ViewModel.SelectedItem is always null. I tried debugging this to see if the binding was working correctly, and it is. When I click on an item in the listbox, the SelectedItem Set is triggered, setting the value... but somewhere inbetween that and the selected changed (In the CS File) It gets reset to Null. Can anyone help out? Thanks

    Read the article

  • Wpf ListBox Trigger not working for IsFocused Property.

    - by viky
    I want to style my ListBox and displaying some Border around it, i want to hide this Border when ListBox gets focus, <Trigger Property="IsFocused" Value="True"> <Setter Property="Visibility" TargetName="border" Value="Collapsed"/> </Trigger> Same thing i m using in TextBox also and it is working properly, why this Trigger not working for ListBox? Edit: i am having this Style for my ListBox <ControlTemplate TargetType="{x:Type local:ListBox}"> <Border SnapsToDevicePixels="true" x:Name="Bd" CornerRadius="5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1"> <Grid> <local:ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </local:ScrollViewer> <Border CornerRadius="5" Background="Red" x:Name="border"> <TextBlock VerticalAlignment="Center" FontWeight="Bold" Foreground="White" Text="{TemplateBinding Message}" FontFamily="Courier New" /> </Border> </Grid> </Border> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="True"> <Setter Property="Visibility" TargetName="border" Value="Collapsed"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> </Trigger> <Trigger Property="IsGrouping" Value="true"> <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> </Trigger> </ControlTemplate.Triggers>

    Read the article

  • 2 listbox to exchange value with DBML

    - by Garcia Julien
    Hi, i'have two Listbox. the think is i do the transfert like : click on field in the left listbox, hit "move right" button and it wll display in the right list box.' The other think it's the first Listbox is bind on Dataset and the second on Entity (Linq-to sql). So when i click on the move next i do that : Dim newSite As New List(Of vw_SiteList) For Each row As SitesDataset.FDDSTRow In SiteAdsListBox.SelectedItems newSite.Add(New vw_SiteList With { _ .SITECODE = row.DEST_COD, _ .SiteDisplay = row.SiteDisplay, _ .CREATEDBY = Environment.GetEnvironmentVariable("USERNAM"), _ .DATECREATED = Now _ }) Next JCDataContext.vw_SiteLists.InsertAllOnSubmit(NewSite) I would like to see now the new field in the right listbox but it isn't there because the field itr's not yet added in the database. How can i do that? Thanks Ju

    Read the article

  • DataTemplate in ListBox

    - by Anu
    Hi, I have tabcontrol,in that by pressing second tab button im adding data to third Tab Listbox.But its not get added. SecondTab function: private void Callbutton_Click(object sender, RoutedEventArgs e) { tab.AddPresetmenu("CALL BUTTON"); } ThirdTab Fucntion: ObservableCollection<DataItem> items = new ObservableCollection<DataItem>(); public void AddPresetmenu(string pMenu) { items.Add(new DataItem(pMenu)); menubox.ItemsSource = items; } Third Tab ListBox XAML: <ListBox x:Name="menubox" Margin="0,5,0,0" Height="244" Width="240" Background="Silver" BorderThickness="0"> </ListBox> I think Im missing something.Please Help me.

    Read the article

  • C# : changing listbox row color?

    - by Meko
    HI. I am trying to changing backround colorof some rows on listbox.I have 2 list that one has all names and it shown on listbox.And second list has some same value with first list.I want to show that when clicking button it will search in listbox and in second list then will change color where found value. I may search in list box like for (int i = 0; i < listBox1.Items.Count; i++) { for (int j = 0; j < students.Count; j++) if (listBox1.Items[i].ToString().Contains(students[j].ToString())) { } } But I don't know which method to change appearances of row.Any help? *EDIT: * HI I made my code like private void ListBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; Brush myBrush = Brushes.Black; Brush myBrush2 = Brushes.Red; g.FillRectangle(new SolidBrush(Color.Silver), e.Bounds); e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault); for (int i = 0; i < listBox1.Items.Count; i++) { for (int j = 0; j < existingStudents.Count; j++) if (listBox1.Items[i].ToString().Contains(existingStudents[j])) { e.Graphics.DrawString(listBox1.Items[i].ToString(), e.Font, myBrush2, e.Bounds, StringFormat.GenericDefault); } } e.DrawFocusRectangle(); } Now it draws my list on listbox.But when I click button first it shows only student that in list with red color but when I click on listbox it again draws all elements.I want that it will show all element ,when I click button it will show all elements and founded element in list with red color.Whre is my mistake?

    Read the article

  • Sorting Listbox in Silverlight (Sketchflow)

    - by gnitez
    I have a Listbox with multiple columns and bound to a data source (XML) as shown below. <ListBox x:Name="lstBox1" Background="#FFC5EFFD" Margin="7,50,10,15" ItemTemplate="{StaticResource ItemsPanelTemplate1}" ItemsSource="{Binding BPICollection}" BorderThickness="0"/> I'm trying to figure out how to sort a particular column in the listbox.

    Read the article

  • Windows Phone app: Binding data in a UserControl which is contained in a ListBox

    - by Alexandros Dafkos
    I have an "AddressListBox" ListBox that contains "AddressDetails" UserControl items, as shown in the .xaml file extract below. The Addresses collection is defined as ObservableCollection< Address Addresses and Street, Number, PostCode, City are properties of the Address class. The binding fails, when I use the "{Binding property}" syntax shown below. The binding succeeds, when I use the "dummy" strings in the commented-out code. I have also tried "{Binding Path=property}" syntax without success. Can you suggest what syntax I should use for binding the data in the user controls? <ListBox x:Name="AddressListBox" DataContext="{StaticResource dataSettings}" ItemsSource="{Binding Path=Addresses, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <!-- <usercontrols:AddressDetails AddressRoad="dummy" AddressNumber="dummy2" AddressPostCode="dummy3" AddressCity="dummy4"> </usercontrols:AddressDetails> --> <usercontrols:AddressDetails AddressRoad="{Binding Street}" AddressNumber="{Binding Number}" AddressPostCode="{Binding PostCode}" AddressCity="{Binding City}"> </usercontrols:AddressDetails> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    Read the article

  • Silverlight 3: ListBox DataTemplate HorizontalAlignment

    - by Lee
    I have a ListBox with it's ItemTemplate bound to a DataTemplate. My problem is I cannot get the elements in the template to stretch to the full width of the ListBox. <ListBox x:Name="listPeople" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" Background="{x:Null}" SelectionMode="Extended" Grid.Row="1" ItemTemplate="{StaticResource PersonViewModel.BrowserDataTemplate}" ItemsSource="{Binding Mode=OneWay, Path=SearchResults}" > </ListBox> <DataTemplate x:Key="PersonViewModel.BrowserDataTemplate"> <ListBoxItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,5,5"> <Border Opacity=".1" x:Name="itemBorder" Background="#FF000000" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="5,5,5,5" MinWidth="100" Height="50"/> </Grid> </ListBoxItem> </DataTemplate> As you can see, I have added a border within the grid to indicate the width of the template. My goal is to see this border expand to the full width of the listbox. Currently its width is determined by its contents or MinWidth, which is the only thing at the moment keeping it visible at all.

    Read the article

  • Win32: How do I get the listbox for a combobox

    - by Adam Tegen
    I'm writing some code and I need to get the window handle of the listbox associated with a combo box. When looking in spy++, it looks like the parent of the listbox is the desktop, not the combo box. How can I programmatically find the listbox window handle? I know I'd be looking for a window class of ComboLBox that belongs to my process, but how do I narrow that down to the specific one I am looking for? Adam

    Read the article

  • Highlight the first row in a ListView and a ListBox Control

    - by Bill
    I am attempting to show both a ListView and ListBox on a Windows Form (C#). The difficulty I am having is in having the first row for both the ListView and ListBox highlighted when the application opens. Could someone please steer me in the right direction so that the first row of both the ListView and ListBox are highlighted when the application opens?

    Read the article

  • Prevent ListBox scrolling to top when updated

    - by WDZ
    I'm trying to build a simple music player with a ListBox playlist. When adding audio files to the playlist, it first fills the ListBox with the filenames and then (on a separate thread) extracts the ID3 data and overwrites the filenames with the correct Artist - Title information (much like Winamp). But while the ListBox is being updated, it's unscrollable, as it always jumps to the top on every item overwrite. Any way to prevent this?

    Read the article

  • Modifying WPF listbox items container when using groupstyle

    - by rulestein
    I have a listbox that is grouping the items with a GroupStyle. I would like add a control at the bottom of the stackpanel that holds all of the groups. This additional control needs to be part of the scrolling content so that the user would scroll to the bottom of the list to see the control. If I were using a listbox without the groups, this task would be easy by modifying the ListBox template. However, with the items grouped, the ListBox template seems to only apply on a per group basis. I can modify the GroupStyle.Panel, but that doesn't allow me to add items to that panel. <----- I would like to add a control to this stackpanel

    Read the article

  • Navigate to browser from selected listbox binded hyperlink (windows phone7)

    - by Ryan Smith
    I am bindind rss items from the net to this page, I cannot Seem to navigate to the link of a selected items hyper link which through binding is string. can anyone help me to navigate to weblink from a listbox item when selected ??? <ListBox Height="712" HorizontalAlignment="Left" Name="listNews" VerticalAlignment="Top" Width="468" SelectionChanged="listNews_SelectionChanged" Margin="0,-22,0,0"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Height="132"> <Image Source="{Binding Avatar}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,7,5,0"/> <StackPanel Width="370"> <TextBlock Text="{Binding Newstitle}" TextWrapping="Wrap" Foreground="#FFC8AB14" FontSize="28" /> <HyperlinkButton Name="{Binding NewsLink}" Content="{Binding NewsLink}" NavigateUri="{Binding NewsLink}" FontSize="18" ClickMode="Press" Click="Selected" /> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> private void listNews_SelectionChanged(object sender, SelectionChangedEventArgs e) { WebBrowserTask webBrowserTask = new WebBrowserTask(); webBrowserTask.URL = **???????;** webBrowserTask.Show();

    Read the article

  • How to Set focus on the 1st Item of Nested Listbox in Silverlight?

    - by Subhen
    Hi , I have a List box which contains another lisbox Inside it. <ListBox x:Name="listBoxParent"> <ListBox.ItemTemplate> <DataTemplate> <Image x:Name="thumbNailImagePath" Source="/this.jpg" Style="{StaticResource ThumbNailPreview}" /> <TextBlock Margin="5" Text="{Binding Smthing}" Style="{StaticResource TitleBlock_Artist}" /> </StackPanel> <StackPanel Style="{StaticResource someStyle}" > <ListBox x:Name="listBoxChild" Loaded="listBoxChild_Loaded" BorderThickness="0"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Margin="5" Text="{Binding myText}" Width="300"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> </ListBox.ItemsPanel> </ListBox> Now while I try to focus to the child List Box : public void listBoxChild_Loaded(object sender, RoutedEventArgs e) { var myListBox = (ListBox)sender; myListBox .ItemsSource = PageVariables.eOUTData;//listboxSongsData; myListBox .SelectedIndex = 0; myListBox .Focus(); } Thanks, Subhen

    Read the article

  • Preventing ListBox scrolling to top when updated

    - by WDZ
    I'm trying to build a simple music player with a ListBox playlist. When adding audio files to the playlist, it first fills the ListBox with the filenames and then (on a separate thread) extracts the ID3 data and overwrites the filenames with the correct Artist - Title information (much like Winamp). But while the ListBox is being updated, it's unscrollable, as it always jumps to the top on every item overwrite. Any way to prevent this? EDIT: The code: public Form1() { //Some initialization code omitted here BindingList<TAG_INFO> trackList = new BindingList<TAG_INFO>(); // The Playlist this.playlist = new System.Windows.Forms.ListBox(); this.playlist.Location = new System.Drawing.Point(12, 12); this.playlist.Name = "playlist"; this.playlist.Size = new System.Drawing.Size(229, 316); this.playlist.DataSource = trackList; } private void playlist_add_Click(object sender, EventArgs e) { //Initialize OpenFileDialog OpenFileDialog opd = new OpenFileDialog(); opd.Filter = "Music (*.WAV; *.MP3; *.FLAC)|*.WAV;*.MP3;*.FLAC|All files (*.*)|*.*"; opd.Title = "Select Music"; opd.Multiselect = true; //Open OpenFileDialog if (DialogResult.OK == opd.ShowDialog()) { //Add opened files to playlist for (int i = 0; opd.FileNames.Length > i; ++i) { if (File.Exists(opd.FileNames[i])) { trackList.Add(new TAG_INFO(opd.FileNames[i])); } } //Initialize BackgroundWorker BackgroundWorker _bw = new BackgroundWorker(); _bw.WorkerReportsProgress = true; _bw.DoWork += new DoWorkEventHandler(thread_trackparser_DoWork); _bw.ProgressChanged += new ProgressChangedEventHandler(_bw_ProgressChanged); //Start ID3 extraction _bw.RunWorkerAsync(); } } void thread_trackparser_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker _bw = sender as BackgroundWorker; for (int i = 0; i < trackList.Count; ++i) { //Pass extracted tag info to _bw_ProgressChanged for thread-safe playlist entry update _bw.ReportProgress(0,new object[2] {i, BassTags.BASS_TAG_GetFromFile(trackList[i].filename)}); } } void _bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { object[] unboxed = e.UserState as object[]; trackList[(int)unboxed[0]] = (unboxed[1] as TAG_INFO); } EDIT2: Much simpler test case: Try scrolling down without selecting an item. The changing ListBox will scroll to the top again. using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public class Form1 : Form { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.listBox1 = new System.Windows.Forms.ListBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // listBox1 this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(0, 0); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(200, 290); // timer1 this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(200, 290); this.Controls.Add(this.listBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Timer timer1; public Form1() { InitializeComponent(); for (int i = 0; i < 45; i++) listBox1.Items.Add(i); } int tickCounter = -1; private void timer1_Tick(object sender, EventArgs e) { if (++tickCounter > 44) tickCounter = 0; listBox1.Items[tickCounter] = ((int)listBox1.Items[tickCounter])+1; } } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

    Read the article

  • WPF Xaml Custom Styling Selected Item Style in a ListBox

    - by John Batdorf
    I have a list box that scrolls images horizontally. I have the following XAML I used blend to create it. It originally had a x:Key on the Style TaregetType line, MSDN said to remove it, as I was getting errors on that. Now I'm getting this error: Error 3 Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. I don't understand how to apply all of this junk that way, I've tried several thing, nothing is working. My goal is to have the selected item's background be white, not blue. Seems like a lot of work for something so small! Thanks. <ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Grid.Row="1" Margin="2,26,2,104" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" > <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="2,0,0,0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> <Setter Property="Background" TargetName="Bd" Value="#FFFFFFFF"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="Selector.IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Image Source="{Binding Image}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >