如何解决Xamarin.Forms 如何在 VisualState 中使用 Xamarin Community Toolkit TouchEffect
我正在使用 VisualState 在我的 XAML 中实现一个条件,但我不知道如何在 VisualState 中更改诸如 Xamarin Community Toolkit TouchEffect 之类的效果的属性,有什么建议吗?
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Red"
HeightRequest="200">
<visualstatemanager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="test">
<VisualState.StateTriggers>
<CompareStateTrigger Property="{Binding sampleBool}" Value="true" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!--Here in the Property there should be some way to refer to the Command property of the TouchEffect-->
<Setter Property="xct:TouchEffect.Command" Value="{Binding sampleCommand}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</visualstatemanager.VisualStateGroups>
</StackLayout>
我试过以这种方式引用,但它引发了以下错误:x:Static:无法找到公共或可访问的内部静态字段、静态属性、常量或枚举值“xct:TouchEffect”。
<Setter Property="{x:Static xct:TouchEffect.Command}" Value="{Binding sampleCommand}" />
我也尝试过使用 Type,但出现此错误:无法解析类型“TouchEffect.Command”
<Setter Property="{x:Type xct:TouchEffect.Command}" Value="{Binding sampleCommand}" />
解决方法
这是正确的做法,我的问题是因为其他原因,我将代码放在 DataTemplate 中,并且必须引用页面视图模型。
在正常情况下,这会起作用:
<Setter Property="xct:TouchEffect.Command" Value="{Binding sampleCommand}" />
在我的情况下,在 DataTemplate 中:
<Setter Property="xct:TouchEffect.Command" Value="{Binding Source={x:Reference SamplePage},Path=BindingContext.sampleCommand}" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。