Ask a questionAsk a question
 

AnswerComboBox Binding to DataClass

  • Thursday, March 01, 2007 9:58 AMHorst Klein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I use a custom LoginCommandData Class to initalize a LoginDialog.

    Public Class LoginCommandData
     
    Inherits DependencyObject
     
    Implements ComponentModel.INotifyPropertyChanged

      Private m_Mandators As IList 
      Private m_Mandator As Common.Data.Mandator

      Public Property Mandators() As IList
       
    Get
         
    Return m_Mandators
       
    End Get
       
    Set(ByVal value As IList)
         
    Dim oldValue As IList = m_Mandators
          m_Mandators = value
          OnCommandDataPropertyChanged(
    New ComponentModel.PropertyChangedEventArgs("Mandators"))
       
    End Set
     
    End Property

      Public
    Property Mandator() As Vito64.Common.Data.Mandator
       
    Get
         
    Return m_Mandator
       
    End Get
       
    Set(ByVal value As Vito64.Common.Data.Mandator)
         
    Dim oldValue As Vito64.Common.Data.Mandator = m_Mandator
          m_Mandator = value
         
    If Not Equals(oldValue, m_Mandators) Then
            
    OnCommandDataPropertyChanged(New ComponentModel.PropertyChangedEventArgs("Mandator"))
          
    End If
       
    End Set
     
    End Property

     

    The Login-Xaml

      <Window.Resources>
        <VFC:LoginCommandData x:Key="LoginData" Password="MyPasswordBox" />
      </Window.Resources>

      <Grid x:Name="MyGrid" DataContext="{StaticResource LoginData}">
        <Label Content="Mandant" x:Name="LabelMandant" Height="23"/>
          <ComboBox Margin="206,143,82,126" IsSynchronizedWithCurrentItem="True"
                    x:Name
    ="ComboBoxMandator"
                    DisplayMemberPath="Name" SelectedValuePath="Id"
                    ItemsSource="{Binding Path=Mandators}"
                    SelectedValue="{Binding Path=Mandator,
                                    Mode=TwoWay,
                                    UpdateSourceTrigger=PropertyChanged}
    ">
          </ComboBox>
      </Grid>

    All I want is that the "Mantator" Property will be set, if it is selected in the ComboBox  
    But it dosn't work.

     

     

Answers

  • Thursday, March 01, 2007 1:51 PMlee dModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I tried the following, seems to work, the selected value is shown in the textblock

    <StackPanel DataContext="{Binding Source={StaticResource mydata}}">
        <ComboBox Name="cb1" SelectedValuePath="CustId" ItemsSource="{Binding Path=CustList}" DisplayMemberPath="Name"
                  SelectedValue="{Binding Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Path=CustId}"></ComboBox>
        <TextBlock Text="{Binding Path=CustId}"></TextBlock>
      </StackPanel>

  • Thursday, March 01, 2007 3:36 PMHorst Klein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Lee

    Thanks a lot for your efforts!

    Analysing your sample with my solution shows two differences:

    1. I was thinking to the the “Id “ in the Mandator class.
      But really I try to set with that binding the Id into the Mandators class.
      Adding a Id to the Mandators Property helps!!!
    2. I our Application the Id is a String
      And if the String is “Nothing” the binding doesn’t work
      L
      Initialise it to an String.Empty helps
      J 
       

    Thanks a lot for your Help!!!!

    Best regards Horst

All Replies

  • Thursday, March 01, 2007 1:51 PMlee dModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I tried the following, seems to work, the selected value is shown in the textblock

    <StackPanel DataContext="{Binding Source={StaticResource mydata}}">
        <ComboBox Name="cb1" SelectedValuePath="CustId" ItemsSource="{Binding Path=CustList}" DisplayMemberPath="Name"
                  SelectedValue="{Binding Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Path=CustId}"></ComboBox>
        <TextBlock Text="{Binding Path=CustId}"></TextBlock>
      </StackPanel>

  • Thursday, March 01, 2007 2:15 PMHorst Klein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Lee

    Thanks for your feedback.

    I think I do the same.

    Can you send your sample at horstDOTkleinATvitodataDOTch?

    Best regards

    Horst

  • Thursday, March 01, 2007 3:36 PMHorst Klein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Lee

    Thanks a lot for your efforts!

    Analysing your sample with my solution shows two differences:

    1. I was thinking to the the “Id “ in the Mandator class.
      But really I try to set with that binding the Id into the Mandators class.
      Adding a Id to the Mandators Property helps!!!
    2. I our Application the Id is a String
      And if the String is “Nothing” the binding doesn’t work
      L
      Initialise it to an String.Empty helps
      J 
       

    Thanks a lot for your Help!!!!

    Best regards Horst