繁体   English   中英

在WPF中更改UserControl内容

[英]Change UserControl content in WPF

我在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中如何实现?

您可以通过将两个新控件添加到容器(例如,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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM