473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Setting DataContext for DataTemplate

Hi All,

Perhaps its because its been a long week, but I just can't seem to figure
out how to bind data in a DataTemplate using DataContext.

The following is in the XAML code:
<Button x:Name="btnRegularDataContext" Margin="5">
<TextBlock Text="{Binding}" />
</Button>

<Button x:Name="btnInDataTemplate" Margin="5">
<Button.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</Button.ContentTemplate>
</Button>

And in the code-behind:
btnRegulareDataContext.DataContext = DateTime.Now.ToShortString();
btnInDataTemplate.DataContext = DateTime.Now.ToShortString();

The first button shows the time, the second does not. What am I missing?!?

Thanks....
Mar 7 '08 #1
0 1586

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I am using a custom control (based on Button), which has in its generic implementation: <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:BasedOnButton">...
2
by: | last post by:
In the operation,it is neccessary to create a new table by smo and then insert some data into the new table by DataContext.Executecommand(). Is it possible to implement in a transaction? If no,any...
0
by: =?Utf-8?B?QmlsbHkgSmFjb2Jz?= | last post by:
I have the following Custom Control that uses a DataTemplate and is Bound to a LightBox object. The template does bind correctly to properties directly on the LightBox object. However my LightBox...
5
by: Andy B | last post by:
I was just wondering, when you create dataContext methods, should you put business logic there to try and minimize pushing data through 2-3 layers of code? or should the business logic still go in...
0
by: Andy B | last post by:
I have a stored proc that selects all from a database table. I drug it from the server explorer onto the o/r designer to make it part of the dataContext. Now I can't figure out how to use it. I...
1
by: Ragesh Krishna | last post by:
Hello, I'm creating a WCF service in which I use LINQ to SQL to do all my data access. I have a couple of architectural questions about using LINQ to SQL from WCF services: 1) What is the...
2
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have a ComboBox that has a DataContext set on it. When a PropertyChanged event is fired (based on a static instance of some class), I'd like to update the DataContext on the combo, but...
1
by: Mike Gleason jr Couturier | last post by:
Hi, Is there any benefit to store a datacontext singleton in an application variable? Should I bother? Should I just create an instance of my datacontext every time my business objects...
2
by: =?Utf-8?B?UGFvbG8=?= | last post by:
How do I pass a DataContext to a button_click event handler. I have the following: public partial class frmMain : Form { public frmMain() { InitializeComponent(); string cnStr =
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.