Button style works at runtime, but Visual Studio shows errors at design time

I use the following class and DependencyProperty to allow the style to set the image for the button:

public static class ImageButton { public static readonly DependencyProperty ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ImageButton), new FrameworkPropertyMetadata((ImageSource)null)); public static ImageSource GetImage(DependencyObject obj) { return (ImageSource)obj.GetValue(ImageProperty); } public static void SetImage(DependencyObject obj, ImageSource value) { obj.SetValue(ImageProperty, value); } } 

I defined the following style (in ImageButton.xaml):

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vcontrols="clr-namespace:Vialis.Led.LedControl5.Controls"> <ControlTemplate x:Key="ImageButtonTemplate" TargetType="Button"> <Image Source="{Binding Path=(vcontrols:ImageButton.Image), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Stretch="Fill" RenderTransformOrigin="0.5, 0.5"> <Image.Resources> <Storyboard x:Key="ShrinkStoryboard"> <DoubleAnimation Storyboard.TargetName="ImageScale" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="0.8" Duration="0:0:0.15" AutoReverse="False"/> <DoubleAnimation Storyboard.TargetName="ImageScale" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="0.8" Duration="0:0:0.15" AutoReverse="False"/> </Storyboard> <Storyboard x:Key="GrowStoryboard"> <DoubleAnimation Storyboard.TargetName="ImageScale" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.0" Duration="0:0:0.15" AutoReverse="False"/> <DoubleAnimation Storyboard.TargetName="ImageScale" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.0" Duration="0:0:0.15" AutoReverse="False"/> </Storyboard> </Image.Resources> <Image.RenderTransform> <ScaleTransform x:Name="ImageScale" ScaleX="1" ScaleY="1" CenterX="1" CenterY="1"/> </Image.RenderTransform> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Pressed" Storyboard="{StaticResource ShrinkStoryboard}"/> <VisualState x:Name="MouseOver" Storyboard="{StaticResource GrowStoryboard}"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Image> </ControlTemplate> <Style x:Key="ImageButtonStyle" TargetType="Button"> <Setter Property="Opacity" Value="0.5"/> <Setter Property="Template" Value="{StaticResource ImageButtonTemplate}"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Opacity" Value="1"/> </Trigger> </Style.Triggers> </Style> </ResourceDictionary> 

And finally, to use it, I have something like this:

 <Button Width="32" Height="32" Style="{StaticResource ImageButtonStyle}" vcontrols:ImageButton.Image="/Images/someimage.png"/> 

When I compile and execute the application, everything works fine. The button receives the image and uses animations defined in the style.

However, during development, Visual Studio cannot visualize it and the XAML editor shows clear lines below the definition of the entire button.

The error information says:

The prefix 'vcontrols' does not map to a namespace.

This applies to using vcontrols in style. If you change the name there, the error will also change, so it is not related to the name selected in the Window / UserControl that uses the button.

What could be the reason for this, and is there a way to fix it so that it works during development?

+4
source share
1 answer

Update 2:

This problem was only with the VS2012 designer (it works fine in VS2010), and it has already been fixed in Visual Studio 2012 Update 3 .

+2
source

Source: https://habr.com/ru/post/1483523/


All Articles