I have a button style with the Image property attached, which is defined in a separate assembly:
<Style x:Key="ExSimpleButton" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="Head" Background="Transparent" BorderBrush="Transparent" BorderThickness="1"> <Grid> <Image x:Name="ButtonImage" Grid.Column="0" Source="{Binding Path=(classes:AttachedImage.Image),RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" HorizontalAlignment="Left"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Head" Property="Background"> <Setter.Value> <SolidColorBrush Color="#FF525252"/> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsMouseDirectlyOver" Value="true"> <Setter TargetName="Head" Property="Effect"> <Setter.Value> <DropShadowEffect ShadowDepth="1"/> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> There is a class that defines the Image property:
namespace ExCtrl.Classes {public class AttachedImage {#region Property Description public static DependencyProperty ImageProperty;
public static ImageSource GetImage(DependencyObject obj) { return (ImageSource)obj.GetValue(ImageProperty); } public static void SetImage(DependencyObject obj, ImageSource value) { obj.SetValue(ImageProperty, value); } #endregion #region Конструктор public AttachedImage() { var metadata = new FrameworkPropertyMetadata((ImageSource)null); ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(AttachedImage), metadata); } #endregion } }
The xaml of the main application window defines the namespace from this assembly:
xmlns:ExClasses="clr-namespace:ExCtrlClasses;assembly=ExCtrl" When you try to set the value of the Image property:
<Button x:Name="btnSysMenu" Grid.Row="1" Grid.Column="0" Style="{DynamicResource ExSimpleButton}" ExClasses:AttachedImage.Image="{StaticResource WinLogo}"/> Floating error: "The value can not be uncertain ..."
Question: What does it mean? And what am I doing wrong? Already the whole head broke !!! Help, who can !!!
StaticResourceDynamicResource, orExClasses:ExSimpleButton- NewViewExClasses:AttachedImage.ExSimpleButton, this assumption .. - NewView