我在wpf中定义了UserControl:
<UserControl x:Class="Views.HideShowDetailsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<DockPanel Background="#FFFFF2CC" Name="HideShowDetailsPanel">
<Button Name="hidePatientDetails"
Background="Transparent"
Margin="10,10"
Width="40"
BorderBrush="Transparent"
BorderThickness="0"
DockPanel.Dock="Right"
Command="{Binding Path=HideDetailsCommand}" >
<Button.Template>
<ControlTemplate TargetType="Button">
<Image Source="../Resources/ArrowRight.png" />
</ControlTemplate>
</Button.Template>
</Button>
</DockPanel>
</UserControl>
我需要通过在激活Command时添加图像画布和另一个按钮来更改其内容。如何在wpf中实现这一目标?
答案 0 :(得分:0)
您可以通过将两个新控件添加到容器中来实现,例如,在您的UC内某处StackPanel
。然后将以下样式分配给StackPanel
:
<Style x:Key="stackStyle" TargetType="StackPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsEnabled, ElementName=hidePatientDetails}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>