473,811 Members | 2,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="btnRegu larDataContext" Margin="5">
<TextBlock Text="{Binding} " />
</Button>

<Button x:Name="btnInDa taTemplate" Margin="5">
<Button.Content Template>
<DataTemplate >
<TextBlock Text="{Binding} " />
</DataTemplate>
</Button.ContentT emplate>
</Button>

And in the code-behind:
btnRegulareData Context.DataCon text = DateTime.Now.To ShortString();
btnInDataTempla te.DataContext = DateTime.Now.To ShortString();

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

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

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

Similar topics

1
4304
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
2581
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 adivise? Thanks.
0
936
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 has a list of Lights and I want to bind the List of lights in the DataTemplate somehow? My attempt to solve the problem was to create a custom control that defined a depencency property and set the dependency property in the DataTemplate. It is...
5
3830
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 another class somewhere making it access the dataContext methods?
0
953
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 don't think I know how to use the ISingleResult type since that is what it returns from what I can see. Any examples of how to do this? any examples I can find are either incomplete, or bad examples. The dataContext is called TestXmlDataContext, the...
1
4570
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 right way to use DataContext in this scenario? The service will obviously be used by multiple clients simultaneously. Should I be creating a "global" DataContext object that I use from within each of
2
9797
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 it seems that I need to set it to null first: Combo1.DataContext = null; Combo1.DataContext = dc;
1
2641
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 need it?
2
2544
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
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10663
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5567
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4357
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.