2012-03-11 33 views
5

Tôi tạo thuộc tính đính kèm cho RadButton để đặt hình ảnh bên trong Nội dung nút Nhưng tôi nhận ngoại lệ này trong thời gian thiết kế trong Visual Studio 2010. Trong Blend 4 i không hiển thị bất kỳ lỗi nào và tại thời gian Run nó làm việc tốt.Không thể tạo 'Đường dẫn' từ văn bản '(RadButtonOnImage: RadButtonImage.Image)'

Đính kèm tài sản:

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}"/> 

Ngoại lệ chi tiết:

System.Reflection.TargetInvocationException 
Exception has been thrown by the target of an invocation. 
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
at System.Delegate.DynamicInvokeImpl(Object[] args) 
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 


System.Windows.Markup.XamlParseException 
Failed to create a 'Path' from the text '(RadButtonOnImage:RadButtonImage.Image)'. 
at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri) 
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) 
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter) 
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField) 
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren) 
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate) 
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container) 
at System.Windows.FrameworkElement.ApplyTemplate() 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Designer.ZoomableViewPresenter.DesignerBackground.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Decorator.MeasureOverride(Size constraint) 
at Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Interop.HwndSource.SetLayoutSize() 
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) 
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value) 
at MS.Internal.DeferredHwndSource.ProcessQueue(Object sender, EventArgs e) 


System.Xaml.XamlParseException 
Prefix 'RadButtonOnImage' does not map to a namespace. 
at MS.Internal.Xaml.XamlContext.ResolveXamlType(String qName, Boolean skipVisibilityCheck) 
at MS.Internal.Xaml.Context.ObjectWriterContext.ServiceProvider_Resolve(String qName) 
at MS.Internal.Xaml.ServiceProviderContext.System.Windows.Markup.IXamlTypeResolver.Resolve(String qName) 
at System.Windows.PropertyPath.GetTypeFromName(String name, Object context) 
at System.Windows.PropertyPath.ResolvePropertyName(String name, Object item, Type ownerType, Object context, Boolean throwOnError) 
at System.Windows.PropertyPath.ResolvePathParts(ITypeDescriptorContext typeDescriptorContext) 
at System.Windows.PropertyPath.PrepareSourceValueInfo(ITypeDescriptorContext typeDescriptorContext) 
at System.Windows.PropertyPath..ctor(String path, ITypeDescriptorContext typeDescriptorContext) 
at System.Windows.PropertyPathConverter.ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, Object source) 
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value) 
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property) 
at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo) 

đâu tôi đang làm sai?

Cảm ơn `s đã được trợ giúp.

+0

Tôi cũng gặp sự cố này trong V2012.3. Vấn đề là trình phân tích cú pháp XAML trong VS không chấp nhận dấu ngoặc đơn trong Đường dẫn, mặc dù nó hoạt động khi được biên dịch. – tofutim

+0

Trong trường hợp của tôi, nó là: sllb: SearchTextBox.FilteredFieldNames = "{Binding (sllb: SearchTextBox.FilteredFieldNames), RelativeSource = {RelativeSource TemplatedParent}}" - dấu ngoặc đơn là vấn đề và phải có cách nào đó để thoát được để làm việc. – tofutim

+1

@tofutim Liệu nó có dừng các lỗi thời gian thiết kế nếu bạn chỉ thêm 'Path =' vào ràng buộc của bạn, như [câu trả lời này gợi ý] (http://stackoverflow.com/a/5832247/302677)? – Rachel

Trả lời

6

Khi liên kết với thuộc tính đính kèm trong WPF 4.0 trở xuống, bạn phải sử dụng thuộc tính Path để tránh bị lỗi thời gian thiết kế.

<Image Source="{Binding Path=(RadButtonOnImage:RadButtonImage.Image), ...}" /> 

Thuộc tính Path không cần thiết trong WPF 4.5 trở lên.

+0

Tôi đồng ý. Từ quan điểm rõ ràng, mã sẽ tốt hơn trong trường hợp này nếu bạn bao gồm 'Path ='. Cho cô ấy tiền thưởng! –

Các vấn đề liên quan