In App.xaml I have defined a template for a custom class that is derived from ContentControl:
<Style x:Key="EntitySymbolStyle" TargetType="aoic:EntitySymbol">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="aoic:EntitySymbol">
<Grid Width="150" Background="White" >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image x:Name="imgSymbol" Grid.Row="0" Source="{TemplateBinding Source}" Cursor="Hand" />
<Image x:Name="imgSelect" Grid.Row="1" Source="/Images/PersoonInsert.png"
Visibility="{TemplateBinding IsSelectEnabled, Converter={StaticResource VisibilityConverter}}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
In my custom ContentControl I defined two dependency properties:
public class EntitySymbol : ContentControl
{
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(ImageSource), typeof(EntitySymbol), null);
public
ImageSource Source
{
get { return GetValue(SourceProperty) as ImageSource; }
set { SetValue(SourceProperty, value); }
}
public
static readonly DependencyProperty IsSelectEnabledProperty =
DependencyProperty.Register("IsSelectEnabled", typeof(bool), typeof(EntitySymbol), null);
public
bool IsSelectEnabled
{
get { return (bool)GetValue(IsSelectEnabledProperty); }
set { SetValue(IsSelectEnabledProperty, value); }
}
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();
}
}
The custom Content control is used as follows:
<
aoic:EntitySymbol Source="/Images/Home.png" IsSelectEnabled="False" />
Does anyone knows what is wrong? Much thanks in advance!