Locked Silverlight ComboboxControl : How to get Displayed Text value

  • Monday, April 23, 2012 8:59 AM
     
      Has Code

    Some code from the Silverlight MVVM application :

    class Animal
    {public string Name; public string Something;}
    
    public AnimalView()
    {
    Animals = new ObservableCollection<Animal>(){new Animal("Dog", "hawhaw"), new Animal("Cat", "miaw")};
    } 

    in the Xaml I have two combobox :

    <ComboBox Height="23"
    HorizontalAlignment="Left"
    Margin="104,15,0,0"
    Name="comboBoxAnimalAdi"
    ItemsSource="{Binding Animals,Mode=TwoWay}"
    DisplayMemberPath="Something"
    VerticalAlignment="Top"
    Width="120" />
    <ComboBox Height="23"
    HorizontalAlignment="Left"
    Margin="104,50,0,0"
    Name="comboBoxAnimal"
    ItemsSource="{Binding Animals,Mode=TwoWay}"
    DisplayMemberPath="Name"
    VerticalAlignment="Top"
    Width="120" /> 

    in the code script, after the action to select an item, i wana check if the displayed text in the combobox is correct (if the developer have made an error on the DisplayMemberPath property. the SilverlightComboBox() gives access to only two properties :
    t.SelectedItem --> the ToString() of the Binded object;
    t.SelectedIndex;


      How to assert the displayed text in the combobox instead of accessing the binded object.


    Issamo san

All Replies

  • Tuesday, April 24, 2012 8:56 AM
    Moderator
     
     

    Hi Issamo,

    I would like to know which version of Silverlight did you use in this scenario? The latest version of Silverlight is not fully support Coded UI Test.


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, April 24, 2012 10:21 AM
     
     
    My silverlight version is 4

    Issamo san

  • Wednesday, April 25, 2012 9:44 AM
     
     

    Make use of UITestControlCOllection someexample=combobox.getchildern();

    string somevalues=someexample[1].Name;

    like this try to use these coding ,hope my hint will get u answer.


    • Edited by Mahendra_P Wednesday, April 25, 2012 9:44 AM
    •  
  • Thursday, April 26, 2012 9:13 AM
    Moderator
     
     

    Hi Issamo,

    As far as I know, the Coded UI Test will recognize the displayed text regardless where it comes from. I would suggest that you could try to get all children controls of this combox and see if there any child control hold these text.


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, April 26, 2012 10:27 AM
     
     

    Hello Tony,

    The problem is not about checking a child and selecting it, its after the selection, I want to check that the displayed text in the combobox is the desired on.


    Issamo san


    • Edited by Issamo-san Thursday, April 26, 2012 10:27 AM
    •  
  • Friday, April 27, 2012 7:17 AM
    Moderator
     
     

    Hi Issamo,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Monday, April 30, 2012 3:05 AM
     
     

    I'm not sure why you don't want to access the binded object. Well, if you want to access the displayed text directly, maybe the following steps are helpful:

    1. call CombBox.GetTemplateChild http://msdn.microsoft.com/en-us/library/system.windows.controls.control.gettemplatechild(v=vs.95).aspx
    2. In the template, it should be ContentPresenter "ContentSite" who is displaying the text. If not, you might use silverlightspy or some other tools to verify it.
    3. Pass the "ContentSite" to GetTemplateChild, and get the instance. Then, get the text.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Jacky Wu
    Microsoft Online Community Support