Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code where a DataGrid is populating the data from my ViewModel. DataGrid can have multiple rows each row have a Button.

I want to show a popup when user will Mouse over on that button.(Currently my Popup is not working)

I am new to WPF, so please help me by considering this. :)

Thank you very much !!

XML
<Grid DataContext="{StaticResource Windows1ViewModel}">
    <StackPanel Orientation="Vertical"
                Margin="20"
                HorizontalAlignment="Center"
                VerticalAlignment="Top">
        <Button Content="Refresh"
                Style="{StaticResource ButtonStyle1}"
                HorizontalAlignment="Left"
                Command="{Binding RefreshDateCommand}" />
        <TextBlock Text="{Binding MyDateTime}" />
        <Button Name="rndm" Content="Randomize Grid Data"
                HorizontalAlignment="Left"
                Margin="0 20 0 0"
                Command="{Binding RefreshPersonsCommand}" />
        <DataGrid ItemsSource="{Binding PersonsCollection}"
                  AutoGenerateColumns="False"
                  CanUserAddRows="False">
            <DataGrid.Columns>                    
                <DataGridTextColumn Binding="{Binding Name, Mode=TwoWay,
                                    UpdateSourceTrigger=PropertyChanged}"
                                    Header="Name (string)" />
                <DataGridTextColumn Binding="{Binding Age}"
                                    IsReadOnly="True"
                                    Header="Age (int)" />
                <DataGridTemplateColumn Header=" "
                                        IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Button Name="btnAdditionalInformation" Content="AI"
                                       Width="40"
                                       Height="20">
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <Grid >
                                <Popup x:Name="popUp" 
                            PlacementTarget="{Binding ElementName= 
                                             btnAdditionalInformation}" 
                            IsOpen="True" Width="200" Height="100">
                                    <StackPanel Orientation="Vertical"
                                                removed="Gray" >
                                        <TextBlock Text="asdf"></TextBlock>
                                        <Button Content="button1"/>
                                    </StackPanel>
                                </Popup>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridCheckBoxColumn Binding="{Binding IsMarried, Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}"
                                        Header="IsMarried (bool)" />
                <DataGridTextColumn Binding="{Binding Height, Mode=TwoWay, 
                                    UpdateSourceTrigger=PropertyChanged}"
                                    Header="Height (double)" />
                <DataGridTextColumn Binding="{Binding BirthDate}"
                                    IsReadOnly="True"
                                    Header="BirthDate (DateTime)" />
                <DataGridTemplateColumn Header="FavoriteColor (SolidColorBrush)"
                                        IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid removed="{Binding FavoriteColor}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <Button Content="can execute command?"
                VerticalAlignment="Top"
                HorizontalAlignment="Left"
                Margin="0 20 0 0"
                Command="{Binding DoNothingCommand}" />
    </StackPanel>

</Grid>
Posted

1 solution

You can put the hover control in a grid and assign the buttons tooltip with the control. Should work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900