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 3300584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:40:32+00:00 2026-05-17T20:40:32+00:00

I defined the following DataTemplate for a LibraryContainer: <DataTemplate x:Key=ContainerItemTemplate> <Grid> <Border BorderThickness=1 BorderBrush=White

  • 0

I defined the following DataTemplate for a LibraryContainer:

<DataTemplate x:Key="ContainerItemTemplate">
            <Grid>
                <Border BorderThickness="1" BorderBrush="White" Margin="3">
                    <s:SurfaceTextBox IsReadOnly="True" Width="120" Text="{Binding Path=name}" Padding="3"/>
                </Border>
                <s:SurfaceButton Content="Expand" Click="SourceFilePressed"></s:SurfaceButton>
            </Grid>
        </DataTemplate>

The SourceFilePressed is the following:

 private void SourceFilePressed(object sender, RoutedEventArgs e)
        {
            Logging.Logger.getInstance().log(sender.ToString());
            e.Handled = true;
        }

In the method SourceFilePressed who can I get the object that is binded to the SurfaceTextBox that is in the same grid as the pressed button? Can I somehow in the DataTemplate attach this object to the Click-Event?

  • 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-17T20:40:32+00:00Added an answer on May 17, 2026 at 8:40 pm

    If I parsed your question correctly, I think you could do this:

    private void SourceFilePressed(object sender, RoutedEventArgs e)
    {
        var obj = (sender as FrameworkElement).DataContext;
    }
    

    To explain: the sender is the source of the event, so it’s the SurfaceButton. It is a FrameworkElement and thus has a DataContext property. The DataContext is an inherited property, so unless you set it explicitly on the SurfaceButton, it will inherit it’s DataContext from its parent (the Grid). The DataTemplate‘s DataContext is the data item it is templating, so you can see that the SurfaceButton will have that same object as its DataContext.

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

Sidebar

Related Questions

I have the following AutoCompleteBox defined inside DataTemplate: <Window.Resources> <DataTemplate x:key=PaneTitleTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition
I defined a DataTemplate the following way: <s:SurfaceWindow.Resources> <ImageBrush x:Key=WindowBackground Stretch=None Opacity=0.6 ImageSource=pack://application:,,,/Resources/WindowBackground.jpg/> <DataTemplate
I have the following definition of a LibraryStack: <s:LibraryStack Name=TaggingContainer Margin=20 Grid.Row=1 Grid.ColumnSpan=2 AllowDrop=True
I defined the following layout: <Grid Name=RootGrid Background={StaticResource WindowBackground} > <s:ScatterView Name=RootScatter> <Viewbox> <s:LibraryContainer
In <Window.Resources> I have defined following style: <Style x:Key=textBlockStyle TargetType=TextBlock> <Setter Property=Margin Value=5,0,5,0/> </Style>
I've defined the following view: <CollectionViewSource x:Key=PatientsView Source={Binding Source={x:Static Application.Current}, Path=Patients}/> Where Patient is
I have defined the following variable: myVar=true now I'd like to run something along
In my application, I defined a DataTemplate for a ListBox to be a grid
I have a combo box with the following DataTemplate: <DataTemplate x:Key=ComboBoxDataTemplate> <StackPanel> <TextBlock Text={Binding
I have a listbox, and I have the following ItemTemplate for it: <DataTemplate x:Key=ScenarioItemTemplate>

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.