473,756 Members | 9,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF Can´t change content of label by databinding

2 New Member
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem.
I need to change content of label when changing content of property "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision.
Does somebody know, please, why content of label doesn´t change when I change content of property "Promena"?

test.xaml
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="DispatcherTimer_CodeProject.test" 
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  4.         xmlns:src="clr-namespace:DispatcherTimer_CodeProject" 
  5.         x:Name="myDispatcherTimer" 
  6.         Title="DispatcherTimer" 
  7.         WindowStyle="None" 
  8.         WindowState="Maximized" 
  9.         ResizeMode="NoResize">  
  10.  
  11.     <Window.Resources>    
  12.         <src:test x:Key="prevod"/>  
  13.         <DataTemplate x:Key="grid1">  
  14.             <Grid x:Name="myGrid" Background="Blue" Cursor="None">  
  15.                 <Grid.RowDefinitions> 
  16.                     <RowDefinition Height="*"/>  
  17.                     <RowDefinition Height="*"/>  
  18.                 </Grid.RowDefinitions> 
  19.                 <Grid.ColumnDefinitions> 
  20.                     <ColumnDefinition/> 
  21.                 </Grid.ColumnDefinitions> 
  22.                 <Label Grid.Row="0"    
  23.                Grid.Column="0"    
  24.                        Name="DatumCas2" 
  25.                Content="{Binding Source={StaticResource prevod}, Path=Promena, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
  26.                VerticalContentAlignment="Center"   
  27.                HorizontalContentAlignment="Center">  
  28.                 </Label> 
  29.             </Grid> 
  30.         </DataTemplate> 
  31.         <DataTemplate x:Key="grid2">  
  32.             <Grid x:Name="myGrid" 
  33.           Background="Black" 
  34.           Cursor="None">  
  35.                 <Grid.RowDefinitions> 
  36.                     <RowDefinition Height="*"/>  
  37.                     <RowDefinition Height="*"/>  
  38.                 </Grid.RowDefinitions> 
  39.                 <Grid.ColumnDefinitions> 
  40.                     <ColumnDefinition/> 
  41.                 </Grid.ColumnDefinitions> 
  42.  
  43.                 <Label Grid.Row="0"   
  44.                Grid.Column="0"   
  45.                Foreground="Red" 
  46.                FontSize="50" 
  47.                Content="CurrentDateAndTime" 
  48.                VerticalContentAlignment="Center" 
  49.                HorizontalContentAlignment="Center">  
  50.                 </Label> 
  51.                 <Label x:Name="DatumCas" 
  52.                Grid.Row="1" 
  53.                Grid.Column="0" 
  54.                Foreground="White" 
  55.                FontSize="30" 
  56.                VerticalContentAlignment="Top" 
  57.                HorizontalContentAlignment="Center">  
  58.                 </Label> 
  59.             </Grid> 
  60.         </DataTemplate> 
  61.     </Window.Resources> 
  62. </Window> 

test.xaml.cs
Expand|Select|Wrap|Line Numbers
  1. using System;  
  2. using System.Windows;  
  3. using System.Windows.Controls;  
  4. using Microsoft.Win32;  
  5. using System.Windows.Input;  
  6. using System.Threading;  
  7. using System.ComponentModel;  
  8. using System.Windows.Threading;  
  9.  
  10. namespace DispatcherTimer_CodeProject  
  11. {  
  12.     public partial class test : Window, INotifyPropertyChanged  
  13.     {     
  14.         public event PropertyChangedEventHandler PropertyChanged;  
  15.  
  16.         private void NotifyPropertyChanged(string info)  
  17.         {  
  18.             if (PropertyChanged != null)  
  19.                 PropertyChanged(this, new PropertyChangedEventArgs(info));  
  20.         }  
  21.  
  22.         private string promena;  
  23.  
  24.         public string Promena  
  25.         {  
  26.             get { return promena; }  
  27.             set { promena = value; NotifyPropertyChanged("Promena"); }  
  28.         }  
  29.  
  30.         public test()  
  31.         {  
  32.  
  33.             InitializeComponent();  
  34.             Promena = "Origin text";  
  35.             this.MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(test_MouseDoubleClick);  
  36.             this.ContentTemplate = FindResource("grid1") as DataTemplate;  
  37.         }  
  38.  
  39.         void test_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)  
  40.         {  
  41.            myDispatcherTimer.Close();  
  42.         }  
  43.  
  44.         private void UserControl_Loaded(object sender, RoutedEventArgs e)  
  45.         {  
  46.             System.Threading.Thread t = new Thread(new ThreadStart(Run));  
  47.             t.SetApartmentState(ApartmentState.STA);  
  48.             t.Start();  
  49.         }  
  50.  
  51.         void Run()  
  52.         {  
  53.             Thread.Sleep(2000);  
  54.             Promena  = "Changed text";  
  55.         }  
  56.     }      
Nov 15 '08 #1
0 4349

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7988
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. <asp:TemplateColumn HeaderText="Rate1"> <ItemTemplate> <asp:Label runat="server" Text='<%# fRate(DataBinder.Eval(Container, "DataItem.RateAgentID")) %>' ID="Label3" NAME="Label3"> </asp:Label>
2
3732
by: mharness | last post by:
Hello, I've tried a number of examples showing how to read the properties of a user control from an aspx file where the code is on the html view of the form but I can't figure out how to read them from the aspx.vb. Can anyone tell me how to declare the user control in the aspx.vb file so that I can read the properties? I did add "Protected WithEvents UC1 As System.Web.UI.UserControl" to the component code behind form but that's the...
1
1743
by: =?Utf-8?B?am9uZWZlcg==?= | last post by:
I keep getting the message after I converted a regular aspx page to now be based on a master page: "Only Content controls are allowed directly in a content page that contains Content controls." What control, or line of Code is causing the error? here is the offending code :
4
2014
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys Just a general query regarding using the AccessDataSource within a website which uses a MasterPage. The layout of my content page is as follows... <asp:Content ID="Content1" ContentPlaceHolderID="cphContent" Runat="Server"> <h1><asp:Label runat="server" Text='<%# Eval("StoryTitle") %>" ID="lblHeading" />
1
2613
by: dhaneshrs | last post by:
I have a small code that shows inactive and active users from the ms access DB. <%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" Title="Welcome" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Drawing" %> <script language="VB" runat="server"> Public Function GetInActiveDays(ByVal strLastLoginDate As String) As Integer Dim date1 As Date = New...
2
1775
RedSunFlowers32
by: RedSunFlowers32 | last post by:
Hi - I am creating a form for my personal business site. I want people to be able to get their own shipping total for the item(s) they have purchased. I have another code from a different file I want to use. I am unclear on which lines to remove to stop the pop-up windows from asking the user to input their information. Could someone please point this out to me? Thank you! Current code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
16
1038
by: m.a | last post by:
Hello, I know that I can do this: <asp:Label runat="server" ID="test" text='<%# Eval("a_field")%>' but how can I do this:
1
19074
by: sweetneel | last post by:
Hi, all In my Asp.net application, I have A Master Page, which has a Label & its id is: "masterpagelabel"; now i want to change the Text of this Label When the Content Page Loads My code is: void Page_Load(...........) Label mylabel=(Label)Master.FindControl("masterpagelabel")
0
9292
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10062
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
9728
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8733
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7282
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
6551
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
5322
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3827
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
3392
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.