c# - How do I use a Trigger to synchronize ListBox selections? -
I have two list boxes that are limited to the same observation archive. Basically a list box is a document tray where I drag & amp; Drop document and other is a regular list box where I give the option of editing the filename. I want to highlight items in both listboxes, for example, when a user selects a document in a listbox (tray), then I want to highlight the list item with the text box in the other and likewise when I use the second list box I click on the text box, then I would like the items in the tray selected. I have my code down
I have the code in the document tray list box.
& lt; ListBox.ItemContainerStyle & gt; & Lt; Style TargetType = "{x: Type ListboxItem}" & gt; & Lt; Setter Property = "Selected" value = "{Binding Path = Selection is done, Mode = Two, UpdatesSource Trigger = Property changes}" /> & Lt; / Style & gt; & Lt; /ListBox.ItemContainerStyle> Similarly in other list boxes I have this type of style
& Lt; Style.Triggers & gt; & Lt; Trigger Properties = "IsKeyboardFocusWithin" Value = "True" & gt; & Lt; Setter property = "isleded" value = "true" & gt; & Lt; / Setter & gt; & Lt; / Catalyst & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /ListBox.ItemContainerStyle> When I select an item in the document tray, the item is being selected in the other list box. When I click on the text box or select an item in another list box, the item tray is not found in the list box. I also noticed that if I comment on Focus then the item is being selected appropriately. I want to promote selection even on the focus.
I'm assuming that you are bound to data in your ListBox code through a property - In the back (visual model or otherwise), for example your items :
& lt; List Box Itemsource = "{Binding Your Items}" & gt; & Lt; ListBox.ItemContainerStyle & gt; ... & lt; / LISTBox.ItemContainerStyle & gt; & Lt; / ListBox & gt; Create another type of property in your code-back archive (such as YourSelectedItem . Then just add the following line to both of your listboxes definitions:
& lt; list box itemsource = "{binding your rectangles}" chosen etam = "{binding selected itam, mode = to y}"> < P> As long as both are tied two-way, then sync them together with each other ISelected (line & lt; setter property = "isseelected" value = "{binding path = isSelected, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged} to use setters in set. "/>> ListBoxes have the properties of handling themselves that if you can bind the code back to a normal item as shown above, I have to try it, but then hope That your trigger will also work because you do not compete with the IsSelected trigger / style Gay I think the key here is that I have found that some times you can not set something through the trigger if you set the same property through a style too , Then use SelectedItem on ListBox Parents instead of a IsSelected style on each item.
Comments
Post a Comment