1

我在另一个上有两个堆栈面板,内部一个具有可见性“折叠”,它的名称为“verborgen”。当鼠标悬停时,内部堆栈面板需要更改为可见性“可见”。所以我使用 TargetName="verborgen"

但是,它总是返回给我“无法识别名称“verborgen”

<DataTemplate x:Key="WastebinTemplate">
            <ContentControl map:MapLayer.Position="{Binding GeoLocation}">
                <ContentControl.Content>
                    <StackPanel> 
                            <TextBlock Background="{StaticResource Blue}" Text="{Binding Barcode}"/>
                        <StackPanel x:Name="verborgen" Visibility="Collapsed"  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.Resources>
                <Style TargetType="StackPanel">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Visibility" Value="Visible" TargetName="verborgen" />
                            <Setter Property="Panel.ZIndex" Value="9999"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataTemplate.Resources>
        </DataTemplate>
4

1 回答 1

1

找到了,问题不是我只是使用了datatemplate.trigger的datatemplate样式

<Window x:Class="Oefening2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:map="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        xmlns:model="clr-namespace:Oefening2.model"
        Title="Wastebins in Kortrijk" WindowState="Maximized">
    <Window.Resources>           
        <model:LocationType x:Key="LocationTypeInstance"/>
        <DataTemplate x:Key="WastebinTemplate">
            <ContentControl map:MapLayer.Position="{Binding GeoLocation}">
                <ContentControl.Content>
                    <StackPanel> 
                            <TextBlock Background="{StaticResource Blue}" Text="{Binding Barcode}"/>
                        <StackPanel x:Name="verborgen" Visibility="Collapsed"  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.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="verborgen" Property="Visibility" Value="Visible"/>
                    <Setter Property="Panel.ZIndex" Value="9999" />
                </Trigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Window.Resources>
    <Grid x:Name="Root">
        <map:Map x:Name="myMap" CredentialsProvider="AnlnVG80DKkOfS5KLoUofPfy8t0a6AdtJvynRT_rxvV8MQ6cy6eEhQ6MHPBd5P3c" ZoomLevel="14" Center="50.8333,3.2667" MouseDoubleClick="MapWithPushpins_MouseDoubleClick">
            <map:MapItemsControl ItemsSource="{Binding Wastebins}" ItemTemplate="{StaticResource WastebinTemplate}" />
        </map:Map>
    </Grid>
</Window>
于 2013-10-21T08:58:28.917 回答