当展开时更改 Microsoft.UI.Xaml.Controls.Expander 的 Title 属性。

huangapple go评论54阅读模式
英文:

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 以查看演示

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.expander?view=windows-app-sdk-1.3

英文:

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

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.expander?view=windows-app-sdk-1.3

答案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.

&lt;!--xmlns:controls=&quot;using:Microsoft.UI.Xaml.Controls&quot;
    xmlns:triggers=&quot;using:Microsoft.Toolkit.Uwp.UI.Triggers&quot;--&gt;

&lt;Grid&gt;
    &lt;VisualStateManager.VisualStateGroups&gt;
        &lt;VisualStateGroup&gt;
            &lt;VisualState&gt;
                &lt;VisualState.StateTriggers&gt;
                    &lt;triggers:IsEqualStateTrigger Value=&quot;{Binding IsExpanded, ElementName=myExpander, Mode=OneWay}&quot; To=&quot;true&quot; /&gt;
                &lt;/VisualState.StateTriggers&gt;
                &lt;VisualState.Setters&gt;
                    &lt;Setter Target=&quot;myExpander.Header&quot; Value=&quot;This is Expander.StateTriggers&quot;/&gt;
                &lt;/VisualState.Setters&gt;
            &lt;/VisualState&gt;
        &lt;/VisualStateGroup&gt;
    &lt;/VisualStateManager.VisualStateGroups&gt;

    &lt;controls:Expander x:Name=&quot;myExpander&quot; Header=&quot;This is Expander.Header&quot; Content=&quot;This is Expander.Content&quot;/&gt;
&lt;/Grid&gt;

huangapple
  • 本文由 发表于 2023年6月12日 13:27:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定