Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Dependency properties are driving me crazy
3 replies. Latest Post by Michel Metselaar on November 27, 2008.
(0)
Michel M...
Member
35 points
43 Posts
11-26-2008 9:15 AM |
In App.xaml I have defined a template for a custom class that is derived from ContentControl:
public
The Source dependency property is used to set the image source of the imgSymbol image. This works great!
The IsSelectEnabled Source dependency property is used to set the visibilty of the imgSelect image.This is giving me the following exception: "Unknown attribute Visibility on element Image"
Here is my value converter to convert a boolean into a Visibility value:
public class VisibilityConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { bool isVisible = (bool)value;
return isVisible ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }}
<
Does anyone knows what is wrong? Much thanks in advance!
bryant
Star
9907 points
1,629 Posts
11-26-2008 10:01 AM |
Can you set a break point on the Convet method of your converter to see if it is actually getting called? I'm wondering if the Static resource is avaiable during binding.
Also, you might be better off moving your template to the themes/generic.xaml file and doing some of your logic during OnApplyTemplate.
11-26-2008 11:13 AM |
Thanks for your response!
Breakpoint wasn't hit. I changed the type of the IsSelectedEnabled property to Visibility and removed the static resource and value converter call. Now it works. But now I don't like the type of the IsSelectedEnabled property, if you know what I mean. What is a clean solution for my case?
I do not understand the advantage of using the themes/generic.xaml file and using the OnApplyTemplate. What kind of logic do you mean in my example? I would realy appreciate another answer.
11-27-2008 12:58 AM |
I studied the possibilities of the OnApplyTemplate method. This method will make it much easier for me to implement my custom control. Thanks for pointing me in the right direction.