how to access property of a custom control in XAML WPF

totoro

I have a custom MyButton with a Text property:

public string Text
{
    get { return aTextBlockInButton.Text; }
    set { aTextBlockInButton.Text = value; }
}

Creating a button in C# and setting its Text property works (Text shows up correctly):

MyButton b = new MyButton(); 
b.Text="hello";

However, when I do this in XAML

<local:MyButton Text="someText" />

I get the error

the member "Text" is not recognized or is not accessible. 

Why? Note that MyButton shows up in Intellisense.

King King

The XAML editor is actually buggy. Sometimes it does not report correctly and gives incorrect error notification. So you should not always believe in what XAML editor tells you. I even had a very long XAML code but the whole code was reported with some problem inside XAML editor, however running/debugging the code anyway is OK. So my advice is believe in yourself first, if there is any actual error, you won't be able to compile and run it.

Sometimes after running the code, coming back to the XAML code, you'll see the error notification has gone away.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Insert XAML into WPF custom control in the editor

From Dev

How can I make WPF instantiate a custom control in my view, using another custom control base class in my XAML?

From Dev

How can I make WPF instantiate a custom control in my view, using another custom control base class in my XAML?

From Dev

WPF: Custom control property was already registered by another custom control error

From Dev

Bind to wpf custom control dependency property for tooltip?

From Dev

WPF custom control, model as dependency property

From Dev

How to set a WPF usercontrol property from XAML?

From Dev

How to use property in WPF XAML from codebehind

From Dev

Using DataTemplate in Generic.xaml for WPF Custom Control

From Dev

Using DataTemplate in Generic.xaml for WPF Custom Control

From Dev

How to specify GroupDescriptions in XAML for a custom DataGrid control?

From Dev

How to bind text to my custom XAML control?

From Dev

How to using XAML to access named control in template

From Dev

Can I set my user control datacontext in xaml via a dependency property bound to a property on the parent control in wpf?

From Dev

How to limit a custom property to available values in XAML

From Dev

How to Bind to Another Control Property in WPF

From Dev

Custom Menu WPF(XAML)

From Dev

WPF set a default value for exist property for custom control

From Dev

Can't access public property on user control wpf c#

From Dev

How to create WPF Custom Control without ControlTemplate?

From Dev

How to access dynamic control WPF in DataTemplate

From Dev

WPF DataGrid, How to bind property on custom DataGridColumn

From Dev

How to do a simple XAML (WPF) conditional binding on the Visibility property

From Dev

Binding winform control property in XAML

From Dev

WPF/XAML Property not found on 'object'

From Dev

Design Definition custom control how access MultiValue

From Dev

How to create a custom WPF XAML style for check box images

From Dev

How to make a custom tool tip template in WPF XAML

From Dev

How to create a custom WPF XAML style for check box images

Related Related

  1. 1

    Insert XAML into WPF custom control in the editor

  2. 2

    How can I make WPF instantiate a custom control in my view, using another custom control base class in my XAML?

  3. 3

    How can I make WPF instantiate a custom control in my view, using another custom control base class in my XAML?

  4. 4

    WPF: Custom control property was already registered by another custom control error

  5. 5

    Bind to wpf custom control dependency property for tooltip?

  6. 6

    WPF custom control, model as dependency property

  7. 7

    How to set a WPF usercontrol property from XAML?

  8. 8

    How to use property in WPF XAML from codebehind

  9. 9

    Using DataTemplate in Generic.xaml for WPF Custom Control

  10. 10

    Using DataTemplate in Generic.xaml for WPF Custom Control

  11. 11

    How to specify GroupDescriptions in XAML for a custom DataGrid control?

  12. 12

    How to bind text to my custom XAML control?

  13. 13

    How to using XAML to access named control in template

  14. 14

    Can I set my user control datacontext in xaml via a dependency property bound to a property on the parent control in wpf?

  15. 15

    How to limit a custom property to available values in XAML

  16. 16

    How to Bind to Another Control Property in WPF

  17. 17

    Custom Menu WPF(XAML)

  18. 18

    WPF set a default value for exist property for custom control

  19. 19

    Can't access public property on user control wpf c#

  20. 20

    How to create WPF Custom Control without ControlTemplate?

  21. 21

    How to access dynamic control WPF in DataTemplate

  22. 22

    WPF DataGrid, How to bind property on custom DataGridColumn

  23. 23

    How to do a simple XAML (WPF) conditional binding on the Visibility property

  24. 24

    Binding winform control property in XAML

  25. 25

    WPF/XAML Property not found on 'object'

  26. 26

    Design Definition custom control how access MultiValue

  27. 27

    How to create a custom WPF XAML style for check box images

  28. 28

    How to make a custom tool tip template in WPF XAML

  29. 29

    How to create a custom WPF XAML style for check box images

HotTag

Archive