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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:55:27+00:00 2026-06-01T22:55:27+00:00

In a DataGrid I use CellTemplate and CellEditingTemplate . In both DataTemplates FrameworkElement.IsLoaded Property

  • 0

In a DataGrid I use CellTemplate and CellEditingTemplate. In both DataTemplates FrameworkElement.IsLoaded Property returns False even if I can see the TextBlock, use the TextBox and Focus() call has returned True.

Is this a bug? Or could someone explain, what’s the reason for this behaviour?


I’ve created this sample application for demonstration purposes.

MainWindow.xaml.cs

namespace WpfApplication
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = new List<string> { "Row1", "Row2" };
        }
    }

    public class FocusAttached
    {
        public static bool GetIsFocused(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsFocusedProperty);
        }

        public static void SetIsFocused(DependencyObject obj, bool value)
        {
            obj.SetValue(IsFocusedProperty, value);
        }

        public static readonly DependencyProperty IsFocusedProperty =
             DependencyProperty.RegisterAttached("IsFocused", typeof(bool), typeof(MainWindow), new UIPropertyMetadata(false, IsFocusedChanged));

        static void IsFocusedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement element = obj as FrameworkElement;

            if ((bool)e.NewValue)
            {
                Console.Write(element);
                Console.Write("  IsLoaded=" + element.IsLoaded);
                Console.Write("  IsVisible=" + element.IsVisible);
                Console.Write("  Focusable=" + element.Focusable);
                // here I call Focus()
                Console.Write("  Focus() returns:" + element.Focus());
                Console.WriteLine("  IsLoaded=" + element.IsLoaded);
            }
        }
    }
}

MainWindow.xaml

<Window x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:WpfApplication"
        Title="Please click on row!" SizeToContent="WidthAndHeight">
    <DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTemplateColumn>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding IsLoaded, RelativeSource={RelativeSource Self}, Mode=OneWay,
                                                  StringFormat='TextBlock in CellTemplate: IsLoaded={0}'}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>

                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <TextBox c:FocusAttached.IsFocused="True"
                                 Text="{Binding IsLoaded, RelativeSource={RelativeSource Self}, Mode=OneWay,
                                                StringFormat='Even after call Focus(): IsLoaded={0}'}" />                                     
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>

        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="Focusable" Value="False" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="IsEditing" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>            
        </DataGrid.CellStyle>
    </DataGrid>
</Window>
  • 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-06-01T22:55:30+00:00Added an answer on June 1, 2026 at 10:55 pm

    First of all, your bindings are useless, because IsLoaded is not a dependency property. There are no notifications, there are no changes of Text.

    IsLoaded is false, because it is deferred like measurement and arrangement. The element is focusable, visible, and enabled, so it can be focused. But there is no guarantee that element already measured and rendered at this point. These actions enqueued in Dispatcher. When they’ll be processed, IsLoaded will be true. Try this:

    static void IsFocusedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        FrameworkElement element = obj as FrameworkElement;
    
        if ((bool)e.NewValue)
        {
            Console.Write(element);
            Console.Write("  IsLoaded=" + element.IsLoaded);
            Console.Write("  IsVisible=" + element.IsVisible);
            Console.Write("  Focusable=" + element.Focusable);
            // here I call Focus() 
            Console.Write("  Focus() returns:" + element.Focus());
            element.Dispatcher.BeginInvoke((Action)(() =>
                {
                    Console.WriteLine("  IsLoaded=" + element.IsLoaded);
                }),
                System.Windows.Threading.DispatcherPriority.Loaded);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can we use datagrid in wpf? I can not see the datagrid control
I use the following DataGrid <DataGrid Grid.Row=1 Grid.Column=1 Name=Grid ItemsSource={Binding} AutoGenerateColumns=False > <DataGrid.Columns> <DataGridTextColumn
I use a WPF Toolkit Datagrid with a LINQ to SQL <my:DataGrid AutoGenerateColumns=False Name=dataGrid2>
Can I use the WPF DataGrid control in the same way I use a
While I'm posting this. I thought, I can use a datagrid. Is so complex
I created a datagrid with dataGridTemplateColumn and I can't use the click on header
I use a Datagrid . In that I put a List of Area like
I am trying to use WpfToolkit DataGrid in Windows Phone 7 project (Silverligt 4)
I have a MultiTrigger that I use to color the values of my DataGrid
I've a custom itemRenderer for my datagrid. To set the actual data I use

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.