Show “pop up window” when is mouser over listBox i

2019-08-21 21:43发布

问题:

I bind observable collection on listBox. I have data tempate on listbox item. It consit one image control and som textBlock.

If is mouse over on some listBox item I would like achieve this behavior:

  • Show PopUp/ToolTip (some "rectangle" with controls) and bind values from listBox current item.
  • And on textBox in item data template I have style, I would like change color of text in textBlock, for example from black to green.

Style is here:

        <Style x:Key="FriedNickStyle" TargetType="TextBlock">
            <Setter Property="Margin" Value="2,2,2,2"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="FontWeight" Value="Medium"/>
            <Setter Property="Foreground" Value="Black"/>
        </Style>

Sory for my english, I have problem how describe this behavior correct. I try many thing but any of them doesn’t work good.

Here is it my style:

     <DataTemplate x:Key="FriendListBoxItemTemplate">
                <Grid Name="RootLayout">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.3*"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="60"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Image Margin="4,4,4,2" Grid.Column="0">
                        <Image.Source >
                            <MultiBinding Converter="{StaticResource avatarConverter}">
                                <Binding Path="ProfilePhoto"></Binding>
                                <Binding Path="StatusInfo.IsLogged"></Binding>
                            </MultiBinding>
                        </Image.Source>
                    </Image>
                    <Grid  Grid.Column="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                    <TextBlock 
                                       Text="{Binding Path=Nick}" 
                                       Style="{StaticResource FriedNickStyle}"
                                       Grid.Column="0" Grid.Row="0">
                    </TextBlock>
                    </Grid>
                </Grid>
                <DataTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <!--SHOW SOME POP UP WINDOW and bind properties from ITEM (VALUE)-->
<!--Change color of textBlock-->
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

Thank everybody who help me.

回答1:

Well, I found this turorial, this article, by the MSDN and another stack overflow's question. Basically, here's how:

<Popup Margin="10,10,0,13"
    Name="Popup1"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Width="194"
    Height="200"
    IsOpen="True">                      // change this to open it

   <TextBlock Name="McTextBlock" Background="LightBlue" >
        This is popup text
   </TextBlock>