![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | Re: TemplateBinding with Image Source Property Thanks for your reply. I will try it. ![]() |
My System Specs![]() |