English 中文(简体)
1. 从XAML全球风格的类型上确定财产
原标题:Set a property from type type with global style in XAML

我想从Xaml的类型中确定一种依赖性财产。 这样做会奏效,但当我以暗中或明确的方式确定这一价值时,就会提出例外(无动于衷的例外)。

I created an empty Silverlight application and added a user control (DataFormControl). Here is the code behind of this control:

    public DataFormControl()
    {
        InitializeComponent();
    }

    public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(DataFormControl), null);
    public string Title
    {
        get { return (string)GetValue(TitleProperty); }
        set { SetValue(TitleProperty, value); }
    }

    public static readonly DependencyProperty TypeToReflectProperty = DependencyProperty.Register("TypeToReflect", typeof(Type), typeof(DataFormControl), null);
    public Type TypeToReflect
    {
        get { return (Type)GetValue(TypeToReflectProperty); }
        set { SetValue(TypeToReflectProperty, value); }
    }

    public string GetCombo()
    {
        string returnValue = (Title ?? "no title") + " ; " + (TypeToReflect != null ? TypeToReflect.Name : "unkown Type");
        return returnValue;
    }


    private void Refresh_Button(object sender, RoutedEventArgs e)
    {
        this.ResultBox.Text = GetCombo();
    }

在这里,《欧洲刑法》:

<Grid x:Name="LayoutRoot">
    <StackPanel Orientation="Horizontal">
        <Button Click="Refresh_Button">Refresh</Button>            
        <TextBlock x:Name="ResultBox" />
    </StackPanel>
</Grid>

现在,问题在于控制着这种控制,并利用全球搭配:

<StackPanel>
        <StackPanel.Resources>
            <Style TargetType="local:DataFormControl">
                <Setter Property="Title" Value="Implicit Name" />
                <Setter Property="TypeToReflect" Value="local:DataFormControl" />
            </Style>
        </StackPanel.Resources>
        <TextBlock FontWeight="Bold">Test App</TextBlock>

        <local:DataFormControl Title="123" />
        <local:DataFormControl Title="Kuh" />
        <local:DataFormControl TypeToReflect="local:DataFormControl" />
        <local:DataFormControl  />
    </StackPanel>

如果我删除“TypeToReflect”——那么,所有工作都是罚款的。 全球产权的捆绑也进行罚款。

这是否是一种骗子?

我需要这种说法,因为我想对此进行思考。

Edit:

例外信息:

Message is always.  [Line: 0 Position: 0]  
ExceptionType: Unhandled Exception  
ExceptionObject: XamlParseException

<>Stacktrace:

 at MS.Internal.XcpImports.CheckHResult(UInt32 hr)  
   at MS.Internal.XcpImports.ConvertStringToTypedCValue(IntPtr pContext, UInt32 cClrTypeName, String clrTypeName, UInt32 cValue, String value, CValue& outVal, Int32& typeIndex)  
   at MS.Internal.SilverlightTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)  
   at MS.Internal.XcpImports.GetManagedPropertyValueFromStyle(Boolean useBuiltInStyle, IManagedPeerBase obj, DependencyProperty property, Object& value)  
   at System.Windows.FrameworkElement.GetValueFromStyle(DependencyProperty property, Object& value)  
   at System.Windows.DependencyObject.EvaluateBaseValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)  
   at System.Windows.DependencyObject.EvaluateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, ValueOperation operation)  
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)  
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty property)  
   at MS.Internal.FrameworkCallbacks.InvalidateProperty(IntPtr nativeTarget, UInt32 propertyId)  

内部欺骗是无效的。

问题回答

你可以写:

{x:Type Type}

页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签