wpf - Databinding selectedindex + 1 -


I would like to bind a text box in which the text of the item given below the item is selected.

Example:

Item 1 - Text = Line Number One Object 2 - Text = Line Number Two - Item 3 - Text = Line Number Three

I Select I am item 2

output

textbox 1 - text = line number two (this is easily bound to the selected image)
Text box - Text = line number <3>

I was thinking about the custom xpath of selected index + 1 but it does not appear to be working

The first attempt failed - see below

You need to implement a IValueConverter and it will be binding to Set to the converter attribute.

Create a class that is derived from the IValueConverter , and in the Convert method, you type the value parameter to (because you will force textbox to list box and convertor to something meaningful.)

Then ListBox 's selected index property.

You want to return the listBox.Items [selectedIndex + 1] method.

You can leave ConvertBack the method is unchanged.

You also have to handle that case where the last item is selected in ListBox , because the index will be out of range 1 perhaps you want to return the first item; You may be null or string.Empty .

Update: Custom list box

As you wish to request, here is a sample that uses the custom list box "ItemAfterSelected" an additional [dependency] property.

First, code for the derived control:

  using System.Windows; Using System.Windows.Controls; Namespace WpfApplication1 {PUBLIC SQUARE PLUSONALISTBOX: LISTBOX {PUBLIC PLUS ONLINEBox () {SelectionMode = SelectionMode.Single; } Select the item after the public commodity {getGalValue (ItemAfterSelectedProperty); } Set {Set Value (item selected property, value); }} Dependency property item for public static readingAdvance = dependency credentials. Registrar ("item option selected", type (object), typef (plusonlist box); Protected Override Zero On-On Challenge (Selection Changed Event Ergus E) {var Nav_ciCent = E. Added Items; If (Neo_services == zero) ItemNumber selected = zero; Else {var last_index = item Number-1; Var index = items. Indochoff (Neo-secretary [0]); After the selection = index & lt; Last_index? Item [index 1]: zero; } Base.OnSelectionChanged (e); Here's a sample window that shows how to use and bind control (you can leave it in the app and run it to see it in action. ).  
  & lt; Window x: orbit = "wpfApplication1.Window1" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http: // Schemas.microsoft.com/winfx/2006/ Xaml "xmlns: custom =" clr-namespace: wpfApplication1 "xmlns: system =" clr-namespace: system; assembly = mscorlib "padding =" 24 "& gt; & Lt; StackPanel & gt; & Lt; Custom: PlusOneListBox x: Name = "custom_listbox" & gt; & Lt; Custom: PlusOneListBox.Items & gt; & Lt; System: String & gt; A & lt; / System: String & gt; & Lt; System: String & gt; Two & lt; / System: String & gt; & Lt; System: String & gt; Three & lt; / System: String & gt; & Lt; System: String & gt; Four & lt; / System: String & gt; & Lt; System: String & gt; Five & lt; / System: String & gt; & Lt; System: String & gt; Six & lt; / System: String & gt; & Lt; / Custom: PlusOneListBox.Items & gt; & Lt; / Custom: PlusOneListBox & gt; & Lt; StackPanel Orientation = "Horizontal" margin = "8" & gt; & Lt; Textbox text = "selected:" /> & Lt; TextBlock Text = "{Binding Selected Itam, ElementName = Custom_listbox}" /> & Lt; / StackPanel & gt; & Lt; StackPanel Orientation = "Horizontal" margin = "8" & gt; & Lt; Text block text = "next:" /> & Lt; TextBlock Text = "{Binding ItemAnifference Selected, ElementName = Custom_Listbox}" /> & Lt; / StackPanel & gt; & Lt; / StackPanel & gt; & Lt; / Window & gt;  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -