0

另一个上有两个堆栈面板。所以第一个堆栈面板总是可见的并且有一个条形码。当鼠标悬停时,我希望第二个堆栈面板 x:Name="Verborgen" 具有可见性“已折叠”以具有可见性“可见性”,现在可见的堆栈面板需要具有 z-Index 9999。

这是项目的 Dropbox 链接: https ://www.dropbox.com/s/8w8horclhfwy4ub/Oefening2.zip

当我将此代码添加到 Window.Resources 时它不起作用,但这有点像我想要的:

        <ControlTemplate x:Key="panelControl" TargetType="StackPanel">
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="Verborgen" Property="Visibility" Value="Visible"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

This is the xaml
<Window.Resources>     
        <model:LocationType x:Key="LocationTypeInstance"/>
        <DataTemplate x:Key="WastebinTemplate">
            <ContentControl map:MapLayer.Position="{Binding GeoLocation}">
                <ContentControl.Content>
                    <StackPanel Name="form"> 
                            <TextBlock Background="{StaticResource Blue}" Text="{Binding Barcode}"/>
                        <StackPanel Visibility="Collapsed" x:Name="Verborgen" Background="{StaticResource Orange}">                             
                            <Button Name="btnRemove" Content="Remove wastebin" Click="btnRemove_Click">
                            </Button>
                            <Label>Adres</Label>
                            <TextBox Name="txbAdres" Text="{Binding Address}"/>
                            <Label>Location type</Label>
                            <ComboBox ItemsSource="{Binding Source={StaticResource LocationTypeInstance}, Path=LocationTypes}" 
                                      DisplayMemberPath="Description" SelectedItem="{Binding LocationType}" SelectedValuePath="ID" SelectedValue="{Binding LocationType.ID}" />
                            <Label>Capaciteit</Label>
                            <Slider Minimum="0" Maximum="100" TickFrequency="10" Value="{Binding Capacity}"></Slider>
                        </StackPanel>
                    </StackPanel>
                </ContentControl.Content>
            </ContentControl>
        </DataTemplate>
    </Window.Resources>
4

1 回答 1

1

尝试这个:

<Window.Resources>
    <Style x:Key="Expandable" TargetType="StackPanel">
        <Setter Property="Visibility" Value="Collapsed" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=StackPanel}, Path=IsMouseOver}" Value="True" >
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <model:LocationType x:Key="LocationTypeInstance"/>
    <DataTemplate x:Key="WastebinTemplate">
        <ContentControl>
            <ContentControl.Content>
                <StackPanel Name="form">
                        <TextBlock Background="{StaticResource Blue}" Text="{Binding Barcode}"/>
                    <StackPanel x:Name="Verborgen" Background="{StaticResource Orange}" Style="{StaticResource Expandable}">
                        <Button Name="btnRemove" Content="Remove wastebin" Click="btnRemove_Click">
                        </Button>
                        <Label>Adres</Label>
                        <TextBox Name="txbAdres" Text="{Binding Address}"/>
                        <Label>Location type</Label>
                        <ComboBox ItemsSource="{Binding Source={StaticResource LocationTypeInstance}, Path=LocationTypes}" 
                                    DisplayMemberPath="Description" SelectedItem="{Binding LocationType}" SelectedValuePath="ID" SelectedValue="{Binding LocationType.ID}" />
                        <Label>Capaciteit</Label>
                        <Slider Minimum="0" Maximum="100" TickFrequency="10" Value="{Binding Capacity}"></Slider>
                    </StackPanel>
                </StackPanel>
            </ContentControl.Content>
        </ContentControl>
    </DataTemplate>

</Window.Resources>
于 2013-10-19T18:00:19.887 回答