Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - TemplateBinding with Image Source Property

 
 
Old 04-12-2006   #1 (permalink)
HolaMan


 
 

TemplateBinding with Image Source Property

Hi~~


I want to binding a image from dependency property of the control
I use template binding to bind a path which is string-type


<Style x:Key="{x:Type local:BitmapButton}" TargetType="{x:Type
local:BitmapButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:BitmapButton}">
<Grid x:Name="Grid" >
<ColumnDefinition/>
<RowDefinition/>
<Image Source=
"{TemplateBinding local:BitmapButton.ImageDefault} Width="Auto"
Height="Auto"/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It
doesn't work

<TextBlock x:Name="ImagePath"
Text="{TemplateBinding
local:BitmapButton.ImageDefault}"/>

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it works
<ContentPresenter ...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

I have no idea why Image does not work but TextBlock's Text work.
Any suggestions? :-(

Thanks

HolaMan


My System SpecsSystem Spec
Old 04-12-2006   #2 (permalink)
Drew Marsh


 
 

Re: TemplateBinding with Image Source Property

HolaMan wrote:

> I have no idea why Image does not work but TextBlock's Text work. Any
> suggestions? :-(


It doesn't work because Image's Source property is not of type string, it
is of type ImageSource. The only reason you can put a string there in XAML
is because when XAML is parsed, the parser uses the converter architecture
to translate the string into a real ImageSource. At runtime though, when
the Binding is occuring, it's gotta be a real ImageSource instance. Therefore,
if your datasource is providing you with a string, you'll need to implement
an IValueConverter[1] to translate that string into a real ImageSource. My
recommendation would be to simply use the ImageSourceConverter's[2] ConvertFrom
method inside of your IValueConverter's Convert implementation.

HTH,
Drew

[1] http://windowssdk.msdn.microsoft.com...eConverter.asp
[2] http://windowssdk.msdn.microsoft.com...eConverter.asp
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 04-12-2006   #3 (permalink)
HolaMan


 
 

Re: TemplateBinding with Image Source Property

Thanks for your reply. I will try it.


My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46