Click here to Skip to main content
15,887,821 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: ToString vs Simple DataTemplate Pin
SledgeHammer0115-Sep-11 13:10
SledgeHammer0115-Sep-11 13:10 
GeneralRe: ToString vs Simple DataTemplate Pin
Member 103390715-Sep-11 22:47
Member 103390715-Sep-11 22:47 
AnswerRe: ToString vs Simple DataTemplate Pin
Kim Breugelmans15-Sep-11 22:54
Kim Breugelmans15-Sep-11 22:54 
AnswerRe: ToString vs Simple DataTemplate Pin
Member 103390715-Sep-11 22:57
Member 103390715-Sep-11 22:57 
GeneralRe: ToString vs Simple DataTemplate Pin
Member 103390717-Sep-11 9:34
Member 103390717-Sep-11 9:34 
AnswerRe: ToString vs Simple DataTemplate Pin
Simon Bang Terkildsen16-Sep-11 6:05
Simon Bang Terkildsen16-Sep-11 6:05 
AnswerRe: Tab Change DataContext becomes Null Pin
Pete O'Hanlon15-Sep-11 4:52
mvePete O'Hanlon15-Sep-11 4:52 
QuestionBind to property in static instance of class Pin
Mc_Topaz14-Sep-11 2:30
Mc_Topaz14-Sep-11 2:30 
I want to display a license version in a TextBox from a property and do it with bindings.

There are two buttons to switch between different license versions and a TextBox to display the license version.

Here is the XAML code:

XML
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <StackPanel Orientation="Vertical">
        <TextBox Name="txtVersion" Text="????"></TextBox>
        <Button Content="Version 1" Click="Version1_Click"></Button>
        <Button Content="Version 2" Click="Version2_Click"></Button>
    </StackPanel>
</Window>


Notice the TextBox Text property, which I don't know how to bind.

The C# code is:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        License license1;
        License license2;

        public MainWindow()
        {
            InitializeComponent();

            license1 = new License("Version 1");
            license2 = new License("Version 2");

            License.Current = license1;

            this.DataContext = this;
            this.PropertyChanged += new PropertyChangedEventHandler(MainWindow_PropertyChanged);
        }

        void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {

        }

        private void Version1_Click(object sender, RoutedEventArgs e)
        {
            License.Current = license1;
            PropertyChanged(this, new PropertyChangedEventArgs("Version"));
        }

        private void Version2_Click(object sender, RoutedEventArgs e)
        {
            License.Current = license2;
            PropertyChanged(this, new PropertyChangedEventArgs("Version"));
        }
    }

    class License
    {
        static License current;
        string version;

        public License(string version)
        {
            this.version = version;
        }

        public static License Current
        {
            get { return current; }
            set { current = value; }
        }

        public string Version
        {
            get { return version; }
        }
    }
}


The class License has the static instance Current property which always give me access to the current Licence. With this I can access the current version like: License.Current.Version

So how do I bind the TextBox's Text to that?

I try also to display the version number every time I press either of the buttons. Is this a working solution?
AnswerRe: Bind to property in static instance of class Pin
Pete O'Hanlon14-Sep-11 3:23
mvePete O'Hanlon14-Sep-11 3:23 
GeneralRe: Bind to property in static instance of class Pin
Mc_Topaz14-Sep-11 4:15
Mc_Topaz14-Sep-11 4:15 
GeneralRe: Bind to property in static instance of class Pin
Ian Shlasko14-Sep-11 4:27
Ian Shlasko14-Sep-11 4:27 
GeneralRe: Bind to property in static instance of class Pin
Mc_Topaz14-Sep-11 4:54
Mc_Topaz14-Sep-11 4:54 
GeneralRe: Bind to property in static instance of class Pin
Ian Shlasko14-Sep-11 5:00
Ian Shlasko14-Sep-11 5:00 
GeneralRe: Bind to property in static instance of class Pin
Pete O'Hanlon14-Sep-11 4:39
mvePete O'Hanlon14-Sep-11 4:39 
GeneralRe: Bind to property in static instance of class Pin
Mc_Topaz14-Sep-11 4:49
Mc_Topaz14-Sep-11 4:49 
QuestionWPF: Unable to set MouseOver effect for ComboBox Pin
All Time Programming13-Sep-11 0:39
All Time Programming13-Sep-11 0:39 
AnswerRe: WPF: Unable to set MouseOver effect for ComboBox Pin
Ian Shlasko14-Sep-11 4:40
Ian Shlasko14-Sep-11 4:40 
QuestionInfinite Scrolling in Canvas Pin
Praveen Raghuvanshi12-Sep-11 2:40
professionalPraveen Raghuvanshi12-Sep-11 2:40 
AnswerRe: Infinite Scrolling in Canvas Pin
tom-englert19-Sep-11 20:42
tom-englert19-Sep-11 20:42 
GeneralUser must not be able to open same site again in other browser or tab Pin
Satish Pai8-Sep-11 7:33
Satish Pai8-Sep-11 7:33 
GeneralRe: User must not be able to open same site again in other browser or tab Pin
Pete O'Hanlon8-Sep-11 9:10
mvePete O'Hanlon8-Sep-11 9:10 
AnswerRe: User must not be able to open same site again in other browser or tab Pin
Simon Bang Terkildsen9-Sep-11 9:08
Simon Bang Terkildsen9-Sep-11 9:08 
QuestionHow to place a multiple window controls inside one window control in WPF Pin
Rocky236-Sep-11 1:52
Rocky236-Sep-11 1:52 
AnswerRe: How to place a multiple window controls inside one window control in WPF Pin
Wayne Gaylard6-Sep-11 2:13
professionalWayne Gaylard6-Sep-11 2:13 
GeneralRe: How to place a multiple window controls inside one window control in WPF Pin
Rocky236-Sep-11 2:47
Rocky236-Sep-11 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.