我正在尝试用路径填充按钮并获取参数超出范围异常。我在我的视图中绑定到模型上的属性。该属性的代码是:
public PunishmentName Name { get; set; }
public Geometry IconData
{
get
{
string data = "";
switch (Name)
{
case PunishmentName.Freeze:
data = "M 0 0 Q 10 10 20 0";
break;
}
Path path = XamlReader.Load("<Path " + "xmlns=" + "'" + "http://schemas.microsoft.com/winfx/2006/xaml/presentation" + "'" + " Data= '" + data + " '/>") as Path;
Geometry geometry = path.Data;
return geometry;
}
}
视图中按钮的代码
<Button Grid.Row="1" BorderBrush="Transparent" >
<Viewbox>
<Path Data="{Binding Punishment.IconData}"/>
</Viewbox>
</Button>
我知道这个问题:这里已经有人问过: Windows Phone 7: How to parse Bezier Path string like in XAML?
我尝试将路径放入网格和画布中,结果相同。
但它在那里没有得到解决......而且我是新来的,所以我无法发表评论,也不愿意提出问题作为答案。我退出卡在这里。我可以想到一个解决方法,但这意味着更多的工作和更丑陋的代码......
例外:
{System.Windows.ApplicationUnhandledExceptionEventArgs}
base: {System.Windows.ApplicationUnhandledExceptionEventArgs}
ExceptionObject: {System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)}
Handled: false
我在带有 Geometry.Parse 的 WPF 应用程序中完成了完全相同的操作,但这仍然不适用于手机...