• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1066
  • 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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