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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:48:25+00:00 2026-05-22T14:48:25+00:00

I would think that this would be incredibly simple, but I’ve searched all over

  • 0

I would think that this would be incredibly simple, but I’ve searched all over and can’t seem to find an answer. I have a DataGridTemplateColumn that I want to use to display a value that isn’t in the DataContext of the DataGrid. I.e. I have an entity that has different names based on the culture. When the grid loads, I want to go get the appropriate name based on the current culture. Every time I see anything about DataGridTemplateColumns, they’re always using the Binding syntax. I can’t do that here. What C# code do I need to access the “nameValue” TextBlock in the following XAML, and in what event handler should I access it:

<Datagrid:DataGridTemplateColumn Header="Name" x:Name="nameField">
    <Datagrid:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock x:Name="nameValue" />
            </StackPanel>
        </DataTemplate>
    </Datagrid:DataGridTemplateColumn.CellTemplate>
</Datagrid:DataGridTemplateColumn>

Thanks to all in advance and I’m sorry for the super n00b question.

  • 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-22T14:48:26+00:00Added an answer on May 22, 2026 at 2:48 pm

    You can still use the binding syntax, it sounds like you just need to bind to a static method instead of the data context of the grid. There is a good reference here http://blog.mrlacey.co.uk/2011/03/binding-to-static-classes-in-windows.html Taking that as an example and modifying for your case.

    First: Setup your grid as you would normally, item source and columns, standard data binding. This will take care of any columns you need from the database or other source.

    Second: In your project add your static class

    namespace StaticBinding
    {
            public class MyStaticClass
            {   
                private static string myStaticProperty;
                public static string MyStaticProperty
                    {
                        get
                        {    return 
                                (CultureInfo.CurrentCulture.Name == "en-US" ? "US" : "Other");
                        }
                    set { myStaticProperty = value; } }
            }
    } 
    

    Third: Add your new resource to app resources

     <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.SampleDataSource" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" 
             x:Class="SilverlightApplication28.App"
             xmlns:myns="clr-namespace:StaticBinding"
             >
    <Application.Resources>
        <myns:MyStaticClass x:Name="MyStaticClass"></myns:MyStaticClass>
    </Application.Resources>
    

    Finally: Set the binding in your TextBlock, if you’ve built your project, you should be able to see the property in the binding editor window.

       <sdk:DataGrid AutoGenerateColumns="False" Height="171" HorizontalAlignment="Left" Margin="61,53,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="263" ItemsSource="{Binding Collection}" LoadingRow="dataGrid1_LoadingRow"   Loaded="dataGrid1_Loaded"     >
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Property1}" Header="Property1"/>
                <sdk:DataGridCheckBoxColumn Binding="{Binding Property2}" Header="Property2"/>
                <sdk:DataGridTextColumn Binding="{Binding Property3}" Header="Property3"/>
                <sdk:DataGridTemplateColumn>
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock x:Name="nameValue" Text="{Binding Source={StaticResource MyStaticClass}, Path=MyStaticProperty}" />
                            </StackPanel>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I thought this would be an incredibly simple thing to do, but
This is something that I think would be very useful. Basically, I'd like there
I would have thought that this would be an easy thing to do, but
My problem is one that you would think is quite common, but I haven't
In Windows, that is. I think the answer to this question is that I
Normally, this would be incredibly easy with tables, but everyone says tables are bad
You would think that launching a bat file from Java would be an easy
From what I've read from Herb Sutter and others you would think that volatile
Would you guys think that a master page should be part of the company's
I would like to think that some of the software I'm writing today will

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.