问题
I'm using DataTrigerBehavior from Behaviors SDK to change System.Windows.Shapes.Path.Data property according to the value of other propery, this is a part of my code:
<Path x:Name="ItemPath" Stretch="Uniform" Grid.Column="0" Fill="#FF646464" Stroke="{x:Null}" StrokeThickness="3">
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding FType, Converter={StaticResource EnumToStringConverter}}" Value="Parent">
<Core:ChangePropertyAction TargetObject="{Binding ElementName=ItemPath}" PropertyName="Data" Value="M15,6H8V3c0-0.484-0.375-1-1-1C6.539,2,6.305,2.287,6,2.54L0.625,7C0.242,7.313,0,7.555,0,8s0.242,0.688,0.625,1L6,13.46 C6.305,13.713,6.539,14,7,14c0.625,0,1-0.516,1-1v-3h7c0.55,0,1-0.45,1-1V7C16,6.45,15.55,6,15,6z"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Path>
It works fine while I'm not compiling project with .net native toolchain, but after compiling project with .Net native I'm getting an argument exception in runtime.
This is an exception details:
Exception thrown: 'System.ArgumentException' in Microsoft.Xaml.Interactions.dll
Additional information: Cannot find a property named Data on type Path.
Why could not be found Data property in the Path class?
Can you help me?
回答1:
There seem to be some problems with Behaviors SDK and .NET Native that are already known and reported.
Here's a quote from Connect bug report:
When you are running in release, you are running under the .NET Native runtime. One thing to note here is that ChangePropertyAction uses reflection during application execution to understand the property and value you are trying to set on an element. For reflection to work sucessfully in these cases in .NET Native runtime, you need to update the default.rd (by default in the Properties folder of your project) with the type information of the property you are trying to access. In the case, you can solve this problem by adding the following line to you default.rd.
<Type Name=”Windows.UI.Xaml.Shapes.Shape” Dynamic=”Required Public” />
Please note that you will need to do the above for the other types referenced by the ChangePropertyAction in your project.
Source: Exception occurs in ChangePropertyAction in release mode UWP application
来源:https://stackoverflow.com/questions/32806462/behavior-sdk-changepropertyaction-generates-argument-exception-in-runtime-when