简体   繁体   English

StackOver可见性在mouseOver上“可见”

[英]StackPanel visiblity “visible” on mouseOver

There are two stackpanels on in the other. 另一个上有两个堆栈面板。 So the first stackpanel is always visible and has a barcode. 因此,第一个堆栈面板始终可见并且具有条形码。 I want the second stackpanel x:Name="Verborgen" with Visiblity "Collapsed" to have Visibility "Visible" when mouseOver, the now visible stackpanel needs to have z-Index 9999. 我希望当mouseOver时,具有可见性“ Collapsed”的第二个堆栈面板x:Name =“ Verborgen”具有可见性“ Visible”,现在可见的堆栈面板需要具有z-Index 9999。

This is the dropbox link to the project: https://www.dropbox.com/s/8w8horclhfwy4ub/Oefening2.zip 这是项目的保管箱链接: https : //www.dropbox.com/s/8w8horclhfwy4ub/Oefening2.zip

It doesn't work when I add this code to Window.Resources but this is kinda what I want: 当我将此代码添加到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>

Try this: 尝试这个:

<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>

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

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