• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1119
  • Last Modified:

WPF User Control Setting Textbox.text....

I have a user control in my WPF application and cannot get the textbox to update?

Main Window:

        public ProductID()
        {
            InitializeComponent();

            var Sbox = new Status();
            Sbox.StatusMessage("HIM");
        }

Control:
        public Status()
        {
            InitializeComponent();
        }

        public void StatusMessage(String StrMessage)
        {
            tbxStatus.Text = StrMessage;
        }    

Any help would be greatly appreciated.
0
cyimxtck
Asked:
cyimxtck
  • 5
  • 3
1 Solution
 
wdosanjosCommented:
It seems you are instantiating a new Status object (line #5), but you're not linking it to your form.  What's the name of the Status user control in the main form?

        public ProductID()
        {
            InitializeComponent();

            var Sbox = new Status();
            Sbox.StatusMessage("HIM");
        }

Open in new window

0
 
cyimxtckAuthor Commented:
<UserControl x:Class="Version.Status"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Version"
             mc:Ignorable="d"
             d:DesignHeight="59"
             d:DesignWidth="388"
             x:Name="StatusMessageControl">
    <Grid Height="57">
        <GroupBox Header="Status:" Name="gbxStatus" Margin="0,-1,0,1">
            <Grid Width="Auto">
                <TextBox Margin="6,6,6,5"
                         Name="tbxStatus"
                         Width="Auto"
                         IsReadOnly="True"
                         Text="{Binding Msg}"/>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>

That is the user control XAML.
0
 
wdosanjosCommented:
Please post your main window XAML.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
cyimxtckAuthor Commented:
<Window xmlns:local="clr-namespace:Version"
        x:Class="Version.ProductID"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Product IDs" Height="300" Width="613" >
    <Grid>
        <StackPanel>
            <local:Status HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </StackPanel>
    </Grid>
</Window>
0
 
wdosanjosCommented:
Please try the following and remove Text="{Binding Msg}" from your User Control:

Main Window XAML:
<Window xmlns:local="clr-namespace:Version"
        x:Class="Version.ProductID"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Product IDs" Height="300" Width="613" >
    <Grid>
        <StackPanel>
            <local:Status x:Name="status" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </StackPanel>
    </Grid>
</Window>

Open in new window


Main Window Code Behind:
        public ProductID()
        {
            InitializeComponent();

            this.status.StatusMessage("HIM");
        }

Open in new window

0
 
cyimxtckAuthor Commented:
Still doesn't work....it comes up blank
0
 
cyimxtckAuthor Commented:
Sorry it does work, forgot to remove the text binding!
0
 
cyimxtckAuthor Commented:
Great Answer!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now