如何刷新相同形式的用户控件 [英] How to refresh user control within same form

查看:47
本文介绍了如何刷新相同形式的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用一个WPF应用程序,其中有多种表单.我不想为每种形式打开新窗口.因此,我们决定使用用户控件.通过隐藏/折叠一个用户控件,我们可以显示另一个用户控件,依此类推.

我在这里有一个问题.当我在一种形式中进行某些更改时,它不会在另一种形式中得到反映,因为用户控件只是隐藏的,所以它们在那里,所以不会刷新.

有什么办法可以刷新/重新加载用户控件?

最重要的问题是,我是否已针对上述问题做出了正确的决定来创建用户控件?

Hi,

I am working with one WPF application, where I have multiple forms. I don''t want to open new window for every form. So we decided to use user control. By hiding/collapsing one user control we can show another and so on.

I have one problem here. When I do some change in one of the form, it is not getting reflect in another form, because user control are just hidden, they are there so not getting refresh.

Is there any way, I can refresh/reload user control?

Most important question is, am I taken correct decision to create user control for problem mentioned above?

推荐答案

您需要实现
INotifyPropertyChanged

接口,使用该接口可以控制用户使用的接口,您需要为所有属性名称设置onPropertyChendg()函数

例如

interface in to you user conrol useing that inter face you need to set onPropertyChendg() function to you all property name

for example

public partial class UserControl1 : UserControl,INotifyPropertyChanged
   {
       public UserControl1()
       {
           InitializeComponent();
       }
       public event PropertyChangedEventHandler PropertyChanged;
       protected void OnPropertyChenged(string propName)
       {
           if (string.IsNullOrEmpty(propName) && PropertyChanged != null)
           {
               PropertyChanged(this, new PropertyChangedEventArgs(propName));
           }
       }

       //in your everty properyt you need to use this method
       private int _Id;

       public int Id
       {
           get { return _Id; }
           set
           {
               _Id = value;
               OnPropertyChenged("Id");
           }
       }


   }



在此通知您控制何时更改应用程序中的值,以控制和更新其值


如果遵循mvvm模式,这将使您的工作更加轻松



here that notify to control when value will be changed in your application that puss to control and update their value


if follow mvvm patter that make you work much easy


这篇关于如何刷新相同形式的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆