Question

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.

This is the dropbox link to the project: 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:

        <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>
Était-ce utile?

La solution

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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top