Click here to Skip to main content
15,891,372 members
Articles / Desktop Programming / WPF

Bindable Converter, Converter Parameter and StringFormat

Rate me:
Please Sign up or sign in to vote.
4.87/5 (12 votes)
18 Sep 2012CPOL5 min read 77.3K   1.5K   20  
How to work around that Binding's Converter, ConvertParameter and StringFormat cannot be specified as dynamic Bindings.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace BindableConverterParameter
{
    public class MyModelView : DependencyObject 
    {
        public MyModelView()
        {
            FirstName = "John";
            ConcatSign = "-";
        }

        public String FirstName
        {
            get { return (String)GetValue(FirstNameProperty); }
            set { SetValue(FirstNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FirstName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FirstNameProperty =
            DependencyProperty.Register("FirstName", typeof(String), typeof(MyModelView), new UIPropertyMetadata("John"));



        public String ConcatSign
        {
            get { return (String)GetValue(ConcatSignProperty); }
            set { SetValue(ConcatSignProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ConcatSign.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ConcatSignProperty =
            DependencyProperty.Register("ConcatSign", typeof(String), typeof(MyModelView), new UIPropertyMetadata("-"));

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Sweden Sweden
Henrik Jonsson is a Microsoft Professional Certified Windows Developer (MCPD) that currently works as an IT consultant in Västerås, Sweden.

Henrik has worked in several small and large software development projects in various roles such as architect, developer, CM and tester.

He regularly reads The Code Project articles to keep updated about .NET development and get new ideas. He has contributed with articles presenting some useful libraries for Undo/Redo, Dynamic Linq Sorting and a Silverlight 5 MultiBinding solution.

Comments and Discussions