开发者

Change WPF window's label content from child user control

I have wpf window named 'GetStarted' with grid which is perent of user control 'Step1'

Step1 s1 = new Step1();
mainGrid.Children.Add(s1);

on step1 is button with this code

 private void btnNext_Click(object sender, RoutedEventArgs e)
 {
            etStarted gt = new GetStarted();
            gt.image0.Visibility = Visibility.Vis开发者_JAVA技巧ible;
            gt.lblSteps.Content= "Step 2 of 5";
 }

but when I press btnNext nothing happens.


Your current code is creating a new Window instance. If you want to get the Window containing the UC you can call Window.GetWindow and then cast to your specific Window type:

    private void btnNext_Click(object sender, RoutedEventArgs e)
    {
        var gt = Window.GetWindow(this) as GetStarted;
        if (gt != null)
        {
            gt.image0.Visibility = Visibility.Visible;
            gt.lblSteps.Content = "Step 2 of 5";
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜