xaml - WPF: Binding an integer to a TextBlock with TemplateBinding -


I have a dependency property in this I have a custom control in WPF type Int is . I have a TextBlock in the template for custom control, and I want to show the value of the integer in TextBlock . But I can not get it to work.

I am using TemplateBinding . If I'm using the same code but dependency property and String type changes then it works fine I but I really rest of the work in I want to be an integer.

How can I do this?

I've written simplified code that shows the problem. Custom Control:

  public class MyCustomControl: Control {static MyCustomControl () {DefaultStyleKeyProperty.OverrideMetadata (Taipf (MyCustomControl), New Fremvrkpraprtimatetata (Taipf (MyCustomControl))); MyIntegerProperty = DependencyProperty.Register ( "MyInteger", type (int), type (MyCustomControl), New Fremvrkpraprtimatetata (0)); } Public at Myintenger {get {return (int) getValue (MyCustomControl.MyIntegerProperty); } Set {Set Value (MyCustomControl.MyIntegerProperty, Value); }} Dependency for public static reading Property MyTea Property; }  

and this is my default template:

  style target type = "{x: type local: myCustomControl}" & gt; & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "{x: Type Local: MyCustomControl}" & gt; & Lt; Border borderTechnication = "1" cornerRadia = "4" borderbrush = "black" background = "esur" & gt; & Lt; StackPanel Orientation = "Vertical" & gt; & Lt; TextBlock Text = "{TemplateBinding MyInteger}" horizontal alignment = "center" /> & Lt; / StackPanel & gt; & Lt; / Border & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;  

More Use:

  & lt; Window x: Class = "custom Kantrolbndingkmanvindo" xmlns = "http://schemas.microsoft.com/winfx / 2006 / xaml / presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006 / Xaml "xmlns: local =" clr-namespace: custom controlbinding "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Grid & gt; & Lt; Local: MyCustomControl width = "100" height = "100" MyInteger = "456" /> & Lt; / Grid & gt;  

What am I doing wrong?

TemplatedParent Try using a regular binding with :

  & lt; TextBlock Text = "{Binding Mayintegr, relative Sors = {Riletivsors Templeted paint}}" horizontal alignment = "center" / & gt; According to  

, this is a limitation of TemplateBinding :

TemplateBinding is a lightweight "binding", it is not < / P>

Automatically support some features of traditional binding as a conversion using the known type converter associated with the target asset.

Comments