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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:06:38+00:00 2026-05-13T20:06:38+00:00

I have a window defined with a style: <Window x:Class=winBorderless x:Name=winBorderless xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:Local=clr-namespace:WindowStyle

  • 0

I have a window defined with a style:

<Window x:Class="winBorderless"
        x:Name="winBorderless"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Local="clr-namespace:WindowStyle"
        Style="{StaticResource Window_Cartesia}"
        WindowStartupLocation="CenterScreen"
        BorderThickness="1"
        BorderBrush="#FF9CAAC1"
        Margin="5"
        Title="[Document Title]">

and the style defined in an application level dictionary:

 <Style x:Key="Window_Cartesia" TargetType="{x:Type Window}">

  <Setter Property="WindowStyle" Value="None"/>
  <Setter Property="AllowsTransparency" Value="True"/>
  <Setter Property="Background" Value="Transparent"/>

  <EventSetter Event="Loaded" Handler="Loaded"/>  
  <EventSetter Event="PreviewKeyDown" Handler="Preview_KeyDown"/>
  <EventSetter Event="MouseMove" Handler="FullScreen_MouseMove"/>

  <Setter Property="Template">

In code behind I have a reference to the Window instance set:

 Win = DirectCast(sender, winBorderless)

This allows access to the window properties as the EventSetters pass references to the various controls. However, it doesn’t provide for access to the controls defined in the style through the window reference as they don’t exist there.

So, what is the best way to reference a control through code behind that is defined in the style. I’d prefer not to iterate the trees to find them but ya gotta do….

  • 1 1 Answer
  • 1 View
  • 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-13T20:06:38+00:00Added an answer on May 13, 2026 at 8:06 pm

    I am assuming that want to access the Controls that originally where defined in the ControlTemplate of you Window. In that case your best bet is to use VisualTreeHelper.GetChild() Additionally, using FrameworkElement.TemplatedParent you can check if the child was created from a ControlTemplate.

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

Sidebar

Related Questions

Consider the following XAML file: <Window x:Class=ExpressionVisualizer.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:sle=clr-namespace:System.Linq.Expressions;assembly=System.Core Title=MainWindow Height=350 Width=525> <Window.Resources>
I have a WPF Window defined in XAML like this: <Window x:Class=com.some.company.window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
In my xaml code, inside the Window.Resources section, I have defined a Data Template
I have a default TextBlock style defined in App.xaml, which seems to also affect
I have the following window, which displays a listview. I defined a style for
In <Window.Resources> I have defined following style: <Style x:Key=textBlockStyle TargetType=TextBlock> <Setter Property=Margin Value=5,0,5,0/> </Style>
I am trying to access commands that are defined in MainWindow.xaml in another window.
So, I have this Window with some controls. In the resources section I've defined
I have a dependency property defined in my window as below: public static readonly
I have a user-defined button, and it may have a Style property which I

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.