如何绑定和刷新静态属性? [英] How to bind and refresh static property?

查看:78
本文介绍了如何绑定和刷新静态属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有查看,查看模型和对象类



  public   class  TestObject 
{

private static string _sTitle;

public static string 标题
{
get ; set ;
}
}





  public   class  TestViewModel:INotifyPropertyChanged 
{

public TestViewModel()
{

}

public 事件 PropertyChangedEventHandler PropertyChanged;

受保护 虚拟 void OnPropertyChanged( string sProperty)
{
if (PropertyChanged!= null ){PropertyChanged( this new PropertyChangedEventArgs(sProperty)); }
}
}





 <  窗口    x:Class   =  Test.MainWindow  

xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation

< /跨度> xmlns:x = http://schemas.microsoft.com/ winfx / 2006 / xaml

xmlns:local = clr-namespace:测试

高度 = 350 宽度 = 525

标题 = < span class =code-keyword> {Binding ???} >
< 网格 >

< / Grid >
< / Window >





如何根据TestObject.Tiltle绑定和刷新?请帮帮我



我尝试了什么:



i完成所有事情.i没有得到任何解决方案

解决方案

检查一下: wpf - 绑定到静态属性 - 堆栈溢出 [ ^ ]

i have view ,view model and objectclass

public class TestObject
   {

       private static string _sTitle;

       public static string Title
       {
           get; set;
       }
   }



public class TestViewModel : INotifyPropertyChanged
   {

     public TestViewModel()
     {

     }

       public event PropertyChangedEventHandler PropertyChanged;

       protected virtual void OnPropertyChanged ( string sProperty )
       {
           if ( PropertyChanged != null ) { PropertyChanged ( this , new PropertyChangedEventArgs ( sProperty ) ); }
       }
   }



<Window x:Class="Test.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:local ="clr-namespace:Test"

        Height="350" Width="525"

      Title="{Binding ???}" >
    <Grid>
       
    </Grid>
</Window>



how to bind and refresh according with TestObject.Tiltle? please help me

What I have tried:

i done every thing.i didnt get any solution

解决方案

Check this: wpf - Binding to static property - Stack Overflow[^]


这篇关于如何绑定和刷新静态属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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