CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: WPF change UserControl textblock from another window

  1. #1
    Join Date
    Aug 2008

    Question WPF change UserControl textblock from another window

    Hey all I am new at WPF so here is my question.

    How can I change the text in a textblock from my mainwindow when the textblock is in the window named curTemp.xaml?

    curTemp.xaml Code:
    public partial class curTemp : UserControl
            public string _valTempChange
                get { return middleForcastCurrentTemp.Text; }
                set { middleForcastCurrentTemp.Text = value; }
            public curTemp()
    Xaml of the above UserControl:

            <TextBlock TextWrapping="Wrap" Padding="5" Foreground="White" Panel.ZIndex="7" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="15,-110,-43,0" Width="198" Height="122">
                    <DropShadowEffect BlurRadius="4" Direction="0" ShadowDepth="0" />
                        <outlineText:OutlinedTextBlock Height="146" Width="192" TextOptions.TextRenderingMode="Aliased" FontFamily="Segoe UI" FontSize="100" x:FieldModifier="public" x:Name="middleForcastCurrentTemp" 
                                                FontWeight="Medium" TextWrapping="Wrap" TextAlignment="Right" Stroke="Black" StrokeThickness="3" Fill="White" Text="10"/>
    And in my MainWindow code:
    public MainWindow()
                curTemp _curTempWindow = new curTemp();
                _curTempWindow._valTempChange = "55";
    When I run that code it never shows "55" in the textblock. It only shows my default text "10".

    What am I doing incorrectly here?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    Re: WPF change UserControl textblock from another window

    You need to implement INotifyPropertyChanged. See

    Not that it matters, but you may want to follow the C# naming conventions for classes, properties, variables, etc. While it doesn't strictly matter for code that is only maintained by you, it does make it harder for others to maintain your code if you ignore the basic conventions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)