`
lovnet
  • 浏览: 6703681 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

How to: Create a Binding in Code

 
阅读更多

http://msdn.microsoft.com/en-us/library/ms742863.aspx

public class MyData : INotifyPropertyChanged
{
    private string myDataProperty;

    public MyData() { }

    public MyData(DateTime dateTime)
    {
        myDataProperty = "Last bound time was " + dateTime.ToLongTimeString();
    }

    public String MyDataProperty
    {
        get { return myDataProperty; }
        set
        {
            myDataProperty = value;
            OnPropertyChanged("MyDataProperty");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string info)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(info));
        }
    }
}

//make a new source
  MyData myDataObject = new MyData(DateTime.Now);      
  Binding myBinding = new Binding("MyDataProperty");
  myBinding.Source = myDataObject;
  myText.SetBinding(TextBlock.TextProperty, myBinding);




分享到:
评论

相关推荐

    Microsoft Visual C# 2013 Step by Step,最新资料

    Create and debug C# applications in Visual Studio 2013 Work with variables, identifiers, statements, operators, and methods Create interfaces and define abstract classes Write robust code that can ...

    Applied.WPF.4.in.Context(第1版)

    Using this book, you’ll learn how to implement world-class WPF solutions in a real-world line of business applications, developing the code from the ground up, and understand how to apply best ...

    Pro WPF in C# 2010 Mar 2010

    example that shows how to create and manage dynamic animations with code. Chapter 17: Control Templates shows you how you can give any WPF control a dramatic new look (and new behavior) by plugging ...

    Getting to Know Vue js

    With Getting to Know Vue.js, you’ll see how to combine reusable code with custom components, allowing you to create snippets of reusable code to suit your specific business needs. You’ll also ...

    Pro JavaFX 2

    In Pro JavaFX 2: A Definitive Guide to Rich Clients with Java Technology, Jim Weaver, Weiqi Gao, Stephen Chin, Dean Iverson, and Johan Vos show you how you can use the JavaFX platform to create rich-...

    Getting to Know Vue.js Learn to Build Single Page

    With Getting to Know Vue.js, you’ll see how to combine reusable code with custom components, allowing you to create snippets of reusable code to suit your specific business needs. You’ll also ...

    CakePHP 1.3 Application Development Cookbook.pdf

    The final section in this chapter shows us how to create highly optimized URLs for our user profiles, and how to build custom Route classes to obtain even more flexibility. Chapter 7, Creating and ...

    Effective C# (Covers C# 4.0) Mar 2010

    Item 43: Use Expressions to Transform Late Binding into Early Binding 261 Item 44: Minimize Dynamic Objects in Public APIs 267 Chapter 6 Miscellaneous 275 Item 45: Minimize Boxing and Unboxing 275 ...

    MySQL and JSON A Practical Programming Guide 2018

    Written by a MySQL Community Manager for Oracle, MySQL and JSON: A Practical Programming Guide shows how to quickly get started using JSON with MySQL and clearly explains the latest tools and ...

    Wrox.Professional.Windows.8.Programming

    This team of authors takes you on a journey through all of the new development features of the Windows 8 platform specifically how to utilize Visual Studio 2012 and the XAML/C# languages to produce ...

    WPF 4 Unleashed

    * Covers everything you need to know about Extensible Application Markup Language (XAML) * Examines the WPF feature areas in incredible depth: controls, layout, resources, data binding, styling, ...

    Mastering Windows 8 C++ App Development

    Starting with coverage of C++/CX (a set of extensions that make working with WinRT easier) and user interface design with XAML, this book shows you how to use major Windows 8 features, including Live ...

    Beginning Python (2005).pdf

    Using the Palette to Create a Window 227 Putting Widgets into the Window 228 Glade Creates an XML Representation of the GUI 230 Try It Out: Building a GUI from a Glade File 231 Creating a Real ...

    wxPython in Action (2006).pdf

    to easily create and maintain literally hundreds of thousands of lines of code, so much of the credit for the vastness of wxPython’s feature set deserves to go to David Beazley and the other ...

    Mastering Backbone.js(PACKT,2015)

    From organizing your code in a logical and physical way, you will go on to delimit view responsibilities and work with complex layouts. Synchronizing models in a two-way binding can be difficult and...

    Mastering.Backbone.js.1783288

    From organizing your code in a logical and physical way, you will go on to delimit view responsibilities and work with complex layouts. Synchronizing models in a two-way binding can be difficult and...

    Vue.js 2 Cookbook 2017年出版760页

    Finally, we take an in-depth look at Vuex for state management and Vue Router to route in your single page applications, and integrate a variety of technologies ranging from Node.js to Electron, and ...

Global site tag (gtag.js) - Google Analytics