【发布时间】:2014-09-15 16:44:22
【问题描述】:
出于各种原因,我尝试在代码中创建和设置样式,但我收到以下应用程序未处理异常。
$exception {System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at Xamarin.Forms.Platform.WinPhone.EntryRenderer.GetDesiredSize(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.Platform.WinPhone.Platform.GetNativeSize(VisualElement view, Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.OnSizeRequest(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.StackLayout.SumOfSizeRequests(Double widthConstraint, Double heightConstraint, Int32& numOfExpanders)
at Xamarin.Forms.StackLayout.LayoutChildren(Double x, Double y, Double width, Double height)
at Xamarin.Forms.Layout.UpdateChildrenLayout()
at Xamarin.Forms.Layout.OnSizeAllocated(Double width, Double height)
at Xamarin.Forms.VisualElement.SizeAllocated(Double width, Double height)
at Xamarin.Forms.Layout.OnChildMeasureInvalidated(Object sender, EventArgs e)
at Xamarin.Forms.VisualElement.InvalidateMeasure()
at Xamarin.Forms.VisualElement.NativeSizeChanged()
at Xamarin.Forms.VisualElement.set_IsNativeStateConsistent(Boolean value)
at Xamarin.Forms.Platform.WinPhone.VisualElementRenderer`2.<SetNativeControl>b__1(Object sender, RoutedEventArgs args)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} System.Exception
我写的代码是
var hintStyle = new Style(typeof(PhoneTextBox));
hintStyle.Setters.Add(
new Setter(
System.Windows.Controls.Control.ForegroundProperty,
view.PlaceholderTextColor.ToBrush())
);
phoneTextBox.HintStyle = hintStyle;
这运行没有错误,但在稍后的某个时间点(我假设在某个渲染点)会发生错误。这是在 Xamarin Forms Renderer 中存在的复杂情况。
我的目标只是能够改变提示颜色。有什么想法可以使这项工作或使用其他方法吗?
【问题讨论】:
-
您要更改 SearchBar 的 WindowsPhone 实现的前景文本颜色吗?如果不是,您要更改哪个控件的外观?
-
不,这是为了更改提示文本颜色。但是控件是 Windows PhoneToolkit PhoneTextBox。这有一个名为 HintStyle 的属性,它接受一个 Style 对象。既然您已经问过了,我可以看到 Styles TargetType 应该是 ContentControl 而不是 PhoneTextBox。已经整理好了...感谢您让我检查 ;-)
标签: c# windows-phone-8 xamarin xamarin.forms