StackPanel可见性在mouseOver上“可见”

时间:2013-10-19 15:42:40

标签: c# xaml visibility stackpanel ismouseover

另一个有两个堆叠面板。 因此,第一个堆栈面板始终可见并且具有条形码。 我想第二个stackpanel x:Name =“Verborgen”与Visiblity“Collapsed”,当mouseOver,现在可见的stackpanel需要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>

1 个答案:

答案 0 :(得分: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>