Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:24:44+00:00 2026-05-15T15:24:44+00:00

in my Silverlight 4 Application, I have an observable list of a user defined

  • 0

in my Silverlight 4 Application, I have an observable list of a user defined class

ObservableCollection<MyClass> myList;

public class MyClass
{
  public string Name { get; set; }
  public string Value { get; set; }
}

I display this list in a ListBox, using databinding and a Template for the ListBoxItems:

<ListBox x:Name="ListBoxCharacteristics" Background="{x:Null}" HorizontalAlignment="Left" >
  <!-- DataTemplate to display the content -->
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel x:Name="StackPanelBorder" Orientation="Horizontal" HorizontalAlignment="Left">
        <TextBox x:Name="TextBoxCharacteristicName" Style="{StaticResource InputTextBox}" Text="{Binding Name}" />
        <TextBox x:Name="TextBoxSep" Style="{StaticResource ReadOnlyTextBox}" Text="=" />
        <TextBox x:Name="TextBoxValue" Style="{StaticResource InputTextBox}" Text="{Binding Value}" LostFocus="FormulaTextBox_LostFocus" TextChanged="Formula_TextChanged"/>

        <Button x:Name="ButtonCheck" Style="{StaticResource RoundWebdingButton}" Content="s" Click="ButtonCheck_Click" />
        <Button x:Name="ButtonAccept" Style="{StaticResource RoundWebdingButton}" Content="a" Click="ButtonAccept_Click" />
        <Button x:Name="ButtonRemove" Style="{StaticResource RoundWebdingButton}" Content="r" Click="ButtonRemove_Click" />
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>

  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>
  </ListBox.ItemContainerStyle>
</ListBox>

The user can change the values in the textboxes and can use the buttons to verify the input, accept it (write it to the underlying model) or remove the entry. To manipulate the underlying model, I need to access the associated item (that is displayed in the listboxitem, where the user has clicked the button).

One idea to get the item was to use the SelectedItem – Property, which will contain the wanted instance of MyClass. Problem is, that clicking on a button or a textbox doesn’t select the containing ListBoxItem. The user would have to manually select the Listboxitem first by clicking somewhere at the item, where no textbox or button is displayed. Otherwise, SelectedItem will be null.
I could get the TextBoxCharacteristicName TextBox via the parent object of the Button, but as the user shall be able to change this content too, I would be unable to get the correct item using this property as identifier.

Any other idea, how to find out, which MyClass-instance is the one that is displayed in the corresponding ListBoxItem?

Thanks in advance,
Frank

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:24:44+00:00Added an answer on May 15, 2026 at 3:24 pm

    Found it! The Button has a property “DataContext”, that contains the MyClass-object I was looking for!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight application that is built from a set of Silverlight class
in my Silverlight 4 Application I have an ObservableCollection that I data bind to
I have a Silverlight application that uses a RadGridView control. When a user updates
In my Silverlight application I have defined a datagrid with an template column containing
I have a Silverlight application which allows the user to switch languages in the
I have silverlight application. What I want is. If my user clicks on Button
Visual Studio 2010 RC -> Silverlight Application We have a library of images that
I have made a silverlight application and I have hosted it on my localhost
I have a Silverlight application that cannot login when it installed in a different
I have a Silverlight application communicating with the server side through WCF services. Initially

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.