none
C# WPF ListView > selectionChanged > ListviewItem >> TextBox = MultiBinding?

    Question

  • Hi there,

    is there any possibility to bind ONE Textbox to several listviewItems? Until now I build a ViewInstance but now i still have no idea how to get forward...
    The PropertyChanged has to keep alive! As you can see in the code below there is only Item binded. How i can make a dessicion what item is selected?
    How i can get the ItemName of pFDBlock for making a switch case or a if dessicion?

    void listViewBlock_SelectionChanged(object sender, SelectionChangedEventArgs e) {
    if(listViewBlock.SelectedItem != null) {
    FDBlock fdBlock = (FDBlock) listViewBlock.SelectedItem;
    MakeView(fdBlock);}

    private
    void MakeView(FDBlock pFDBlock){
    textBoxMainDetail.Text = pFDBlock.Bez;
    }

    • Moved by Mathias Schiffer Friday, June 26, 2009 10:07 AM English Language Post (From:Windows Presentation Foundation (WPF))
    Friday, June 26, 2009 9:19 AM

Answers

  • Hi,

    If it is the type of the object which is bound to ListView, which you mean by ItemName, then you can do the following.

    if (listViewBlock.SelectedItem is FDBlock)
                {
                   textBoxMainDetail.Text = ((FDBlock)listViewBlock.SelectedItem).Bez; 
                 }
    Friday, June 26, 2009 11:35 AM
  • Hi,
    Yes you are right. Make a two way binding so that it updates to the object aswell.
    To get the textbox, in the selected index changed object sender when you cast it to a text box you must get the value.

    Hopefully,
    MRLF
    • Proposed as answer by MRLF Saturday, June 27, 2009 7:35 AM
    • Marked as answer by Jim Zhou - MSFT Thursday, July 02, 2009 6:21 AM
    Saturday, June 27, 2009 7:35 AM

All replies

  • Hi,

    If it is the type of the object which is bound to ListView, which you mean by ItemName, then you can do the following.

    if (listViewBlock.SelectedItem is FDBlock)
                {
                   textBoxMainDetail.Text = ((FDBlock)listViewBlock.SelectedItem).Bez; 
                 }
    Friday, June 26, 2009 11:35 AM
  • Hi,

    thanx for your answer! Mh the "main"problem is to take the text back its source. There is a DataTemplated list wich contains several TextBoxes. I´d like to show the one, wich is selected,  in a big normal textbox above the ListView. The prop is to keep the Data alive - Maybe i should use a DataTrigger wich directly make a 2 way bind....
    Friday, June 26, 2009 2:43 PM
  • Hi,
    Yes you are right. Make a two way binding so that it updates to the object aswell.
    To get the textbox, in the selected index changed object sender when you cast it to a text box you must get the value.

    Hopefully,
    MRLF
    • Proposed as answer by MRLF Saturday, June 27, 2009 7:35 AM
    • Marked as answer by Jim Zhou - MSFT Thursday, July 02, 2009 6:21 AM
    Saturday, June 27, 2009 7:35 AM
  • Hi,

    The two posts above gave good clue in this case, if you feel it still does not resolve your issue, you can post a simplified sample for us to repro. so that we can clearly have ideas of where you are trying to do.

    Thanks.
    Jim Zhou -MSFT
    Wednesday, July 01, 2009 11:22 AM