C#C
C#2y ago
17 replies
quantum

WPF TextBlock Text binding

Hello i am working with wpf for very first time. I am trying to make a textbox with placeholder but when i try to use this resource it says The member "Placeholder" is not recognized or is not accessible.
Here is my code

PlaceholderTextbox.xaml
<Grid>
    <TextBlock 
        x:Name="txtPlaceholder" 
        VerticalAlignment="Center"
        HorizontalAlignment="Left"
        FontSize="16"
        Padding="10,0,0,0"
        Foreground="#a3a3a4"
        Text="{Binding Placeholder}"
        />
</Grid>

PlaceholderTextbox.xaml.cs
        public PlaceholderTextbox()
        {
            InitializeComponent();
            DataContext = new CustomTextboxViewmodel();
        }


PlaceholderTextboxVM.cs
    class CustomTextboxViewmodel : Base
    {
        private string placeholder = "Placeholder";

        public string Placeholder
        {
            get { return placeholder; }
            set { placeholder = value; OnPropertyChanged(); }
        }
    }
Was this page helpful?