templatebinding

Template Binding in Control template

这一生的挚爱 提交于 2019-11-26 08:16:26
问题 I have the following control template. I wish to set the source property for the image control in the control template using Template Binding. But since this is a control template for button control and the button control doesn\'t have source property, i can\'t use TemplateBinding in this case. <ControlTemplate x:Key=\"BtnTemplate\" TargetType=\"Button\"> <Border CornerRadius=\"5\" Margin=\"15\" Cursor=\"Hand\"> <StackPanel> <Image Name=\"Img\" Style=\"{StaticResource ImageStyle}\" Source=\

WPF TemplateBinding vs RelativeSource TemplatedParent

孤街浪徒 提交于 2019-11-26 00:46:02
问题 What is the difference between these 2 bindings: <ControlTemplate TargetType=\"{x:Type Button}\"> <Border BorderBrush=\"{TemplateBinding Property=Background}\"> <ContentPresenter /> </Border> </ControlTemplate> and <ControlTemplate TargetType=\"{x:Type Button}\"> <Border BorderBrush=\"{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}\"> <ContentPresenter /> </Border> </ControlTemplate> ? 回答1: TemplateBinding is not quite the same thing. MSDN docs are often written by