I'm trying to fill a button with a path and get an argument out of range exception. I'm binding in my View to a property on a model. Code for the property is:
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;
}
}
code for the button in the view
<Button Grid.Row="1" BorderBrush="Transparent" >
<Viewbox>
<Path Data="{Binding Punishment.IconData}"/>
</Viewbox>
</Button>
I know this question: is already been asked here: Windows Phone 7: How to parse Bezier Path string like in XAML?
I tried putting the Path into a grid and a canvas as well with the same result.
But it does'nt get solved there...And i'me new here so i can't comment and don't feel comfortable asking a question as an answer. I'me quit stuck here. I can think of a work around but that would mean a lot more work and uglier code...
The exception:
{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
I've done exactly the same in a WPF application with Geometry.Parse but this still is'nt avalable for the phone...