xaml에서 'Type'형식의 종속성 속성을 설정하고 싶습니다. 이 잘 작동하지만 암시 적 또는 명시 적 스타일 다음 예외 (처리되지 않은 예외) throw됩니다이 값을 설정할 때.XAML에서 전역 형식으로 'type'유형의 속성 설정
빈 Silverlight 응용 프로그램을 만들고 사용자 정의 컨트롤 (DataFormControl)을 추가했습니다. XAML 코드 여기
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();
}
그리고 :
<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>
: 이제이 참조하고 글로벌 스타일을 사용하여 컨트롤의 문제 occurres
<Grid x:Name="LayoutRoot">
<StackPanel Orientation="Horizontal">
<Button Click="Refresh_Button">Refresh</Button>
<TextBlock x:Name="ResultBox" />
</StackPanel>
</Grid>
여기 는이 컨트롤의 뒤에 코드
"TypeToReflect"-Setter를 제거하면 정상적으로 작동합니다. title 속성의 전역 스타일 역시 잘 작동합니다.
버그입니까? 아니면 해결 방법이 있습니까?
반사를 사용하고 싶기 때문에 유형이 필요합니다.
편집 :
예외 정보 :
Message is always. [Line: 0 Position: 0]
ExceptionType: Unhandled Exception
ExceptionObject: XamlParseException
스택 트레이스 :
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)
의 InnerException가 null입니다.
예외의'InnerException'은 무엇입니까이 대답을 살펴보십시오? 스택 트레이스는 어떻게 생겼습니까? – svick
http://stackoverflow.com/questions/6028276/missing-style-triggers-and-xtype-why 당신 말이 맞아. 비슷한 해결책이 있습니다. – Jens