C# 未能创建';路径';从文本';(RadButtonNonImage:RadButtonImage.Image)和#x27;
我为我的RadButton创建了一个attach属性来设置按钮内容中的图像,但在VisualStudio2010的设计时遇到了这个异常。在Blend 4中,我没有显示任何错误,在运行时它工作正常 附加属性:C# 未能创建';路径';从文本';(RadButtonNonImage:RadButtonImage.Image)和#x27;,c#,.net,wpf,xaml,telerik,C#,.net,Wpf,Xaml,Telerik,我为我的RadButton创建了一个attach属性来设置按钮内容中的图像,但在VisualStudio2010的设计时遇到了这个异常。在Blend 4中,我没有显示任何错误,在运行时它工作正常 附加属性: namespace SmartSoft.GTS.RadButton { public class RadButtonImage { public static readonly DependencyProperty ImagePropery; public static
namespace SmartSoft.GTS.RadButton
{
public class RadButtonImage
{
public static readonly DependencyProperty ImagePropery;
public static ImageSource GetImage(DependencyObject obj)
{
return (ImageSource)obj.GetValue(ImagePropery);
}
public static void SetImage(DependencyObject obj,ImageSource Value)
{
obj.SetValue(ImagePropery,Value);
}
static RadButtonImage()
{
ImagePropery = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(RadButtonImage), new PropertyMetadata((ImageSource)null));
}
}
}
XAML:
xmlns:RadButtonOnImage="clr-namespace:SmartSoft.GTS.RadButton"
<Style x:Key="ImageOnRadButton" TargetType="{x:Type telerik:RadButton}">
<Setter Property="FontSize" Value="13.333"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding (RadButtonOnImage:RadButtonImage.Image), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadButton}}}"/>
<TextBlock Text="{TemplateBinding Content}" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,5,0"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<telerik:RadButton Content="New" RadButtonOnImage:RadButtonImage.Image="Images/Buttons/Clear.png" Style="{DynamicResource ImageOnRadButton}"/>
我哪里做错了
谢谢你的帮助 在WPF 4.0或更低版本中绑定到附加属性时,您必须实际使用
路径
属性以避免出现设计时错误
<Image Source="{Binding Path=(RadButtonOnImage:RadButtonImage.Image), ...}" />
Path
属性在WPF 4.5及更高版本中不需要。我在V2012.3中也有这个问题。问题是VS中的XAML解析器不批准路径中的括号,即使它在编译时可以工作。在我的例子中是:sllb:SearchTextBox.FilteredFieldNames=“{Binding(sllb:SearchTextBox.FilteredFieldNames),RelativeSource={RelativeSource TemplatedParent}”-括号是问题所在,必须进行一些转义才能工作。@tofutim如果您只是将Path=
添加到绑定中,它是否会停止给您提供设计时错误,如?@Rachel it works!(我只是需要重建才能看到变化。)@Rachel你应该写下解决方案。我同意。从清晰的角度来看,如果您仍然包含Path=
,那么在本例中代码会更好。把赏金给她!
<Image Source="{Binding Path=(RadButtonOnImage:RadButtonImage.Image), ...}" />