英文:
Change Microsoft.UI.Xaml.Controls.Expander Title property when expanded
问题
这可以仅使用 UWP 中的 XAML 来完成吗?如果可以,如何完成?
源代码:https://github.com/microsoft/microsoft-ui-xaml/tree/main/dev/Expander
运行:winui2gallery://item/Expander
以查看演示
英文:
Can this be done with just Xaml in UWP? If so how?
source code: https://github.com/microsoft/microsoft-ui-xaml/tree/main/dev/Expander
run: winui2gallery://item/Expander
for demo
答案1
得分: 1
你可以在 XAML 中使用 IsEqualStateTrigger,在 NuGet 包 Microsoft.Toolkit.Uwp.UI.Triggers 中处理 Expander 展开事件。
<!--xmlns:controls="using:Microsoft.UI.Xaml.Controls"
xmlns:triggers="using:Microsoft.Toolkit.Uwp.UI.Triggers"-->
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<triggers:IsEqualStateTrigger Value="{Binding IsExpanded, ElementName=myExpander, Mode=OneWay}" To="true" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myExpander.Header" Value="This is Expander.StateTriggers"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<controls:Expander x:Name="myExpander" Header="This is Expander.Header" Content="This is Expander.Content"/>
</Grid>
英文:
You can use IsEqualStateTrigger in NuGet package Microsoft.Toolkit.Uwp.UI.Triggers to handle Expander expansion events in XAML.
<!--xmlns:controls="using:Microsoft.UI.Xaml.Controls"
xmlns:triggers="using:Microsoft.Toolkit.Uwp.UI.Triggers"-->
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<triggers:IsEqualStateTrigger Value="{Binding IsExpanded, ElementName=myExpander, Mode=OneWay}" To="true" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myExpander.Header" Value="This is Expander.StateTriggers"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<controls:Expander x:Name="myExpander" Header="This is Expander.Header" Content="This is Expander.Content"/>
</Grid>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论