【发布时间】:2021-08-04 13:49:22
【问题描述】:
我正在使用 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: 无法找到名为“Command”的公共或可访问的内部静态字段、静态属性、常量或枚举值“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}" />
【问题讨论】:
-
我认为您需要创建一个触摸效果(将其添加到您的 XAML),在 XAML 中为其命名,然后以某种方式引用该名称。对不起,这很模糊,但也许能给你一个线索。是否有指向您正在关注的使用触摸效果的示例的链接?
-
嗨@ToolmakerSteve,我使用此存储库作为参考,因为它是与 XamarinCommunityToolkit 合并的存储库并且有很多示例,尽管我找不到有关如何引用这些的线索或文档VisualState 中的效果:github.com/AndreiMisiukevich/TouchEffect
-
好的,这有帮助。在声明附加了 TouchEffect 的元素时,是否可以设置初始属性值?类似于 TouchEffectSample/TogglePage.xaml 第 22-46 行,特别是第 31-41 行?那么在VisualState中应该是类似的Setter。您是否尝试过简单的
<Setter Property="xct:TouchEffect.Command" Value=...?警告:我没有尝试过类似的代码。将此语法视为类似于使用Grid.Column作为网格内元素的属性。 -
@ToolmakerSteve 我之前也尝试过,但 XAML 向我显示以下错误:Type 'xct:TouchEffect' is used as a markup extension but does not derived from MarkupExtension.
-
@ToolmakerSteve 是的,它允许在仅在控件中使用时设置值。很奇怪,在 VisualState 或 Trigger 中没有简单的方法来引用效果的属性。
标签: xaml xamarin.forms xamarin-community-toolkit