(WPF MVVM) 我正在尝试使用我自己的样式和 ContentTemplate->StaticResource->DataTemplate 的组合来制作暂停/播放按钮。我将 DataTemplate 设置为矢量图形数据。我为暂停按钮和播放按钮准备了 2 个矢量图形。我的目标:如果我单击暂停按钮,ContentTemplate 将“切换”到 Play-Button-DataTemplate,并且按钮变为 Play-Button。我知道我需要绑定按钮的 Click-event 或使用 RelayCommand 来做 Pause/Play 操作(在我的代码片段中我没有绑定 Click 事件),但我不知道如何绑定 ContentTemplate 来获取我需要的效果。先感谢您。
<controls:MyButton x:Name="btnPause" AutomationProperties.Name="btnPause" Style="{StaticResource MyButtonStyle}" ContentTemplate="{StaticResource dtmpPause}" />
<DataTemplate x:Name="dtmpPause">
<Path x:Name="pathPause" Fill="White" Stretch="Uniform" Data="M314.00598,126.271 L379.52698,126.271 L379.52698,440.672 L314.00598,440.672 z M187.40198,126.271 L252.92398,126.271 L252.92398,440.672 L187.40198,440.672 z M283.45901,34.240997 C146.03,34.240997 34.229004,146.043 34.229004,283.45697 C34.229004,420.88702 146.03,532.70099 283.45901,532.70099 C420.88699,532.70099 532.70203,420.88702 532.70203,283.45697 C532.70203,146.043 420.88699,34.240997 283.45901,34.240997 z M283.45901,0 C439.772,0 566.92999,127.158 566.92999,283.45697 C566.92999,439.771 439.772,566.94299 283.45901,566.94299 C127.15799,566.94299 0,439.771 0,283.45697 C0,127.158 127.15799,0 283.45901,0 z"/>
</DataTemplate>
<DataTemplate x:Name="dtmpPlay">
<Path x:Name="pathPlay" Fill="White" Stretch="Uniform" Data="M269.00003,121.50002 L298.00003,121.50002 L298.00003,445.50003 L269.00003,445.50003 z M283.5,41.621429 L41.620132,283.50198 L283.5,525.37958 L525.37982,283.50198 z M283.5,0 L566.99994,283.50198 L283.5,567 L0,283.50198 z"/>
</DataTemplate>