Guest User

Untitled

a guest
Nov 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public class MyPopup : Popup
  2. {
  3. static MyPopup()
  4. {
  5. DefaultStyleKeyProperty.OverrideMetadata(typeof(MyPopup), new FrameworkPropertyMetadata(typeof(MyPopup)));
  6. }
  7. }
  8.  
  9. <Style x:Key="MyPopupStyle" TargetType="{x:Type local:MyPopup}">
  10. <Setter Property="Placement" Value="MousePoint" />
  11. <Setter Property="Child">
  12. <Setter.Value>
  13. <Border
  14. Width="100"
  15. Height="100"
  16. Background="HotPink" />
  17. </Setter.Value>
  18. </Setter>
  19. <Setter Property="IsOpen" Value="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.IsMouseOver, Mode=OneWay}" />
  20. </Style>
  21.  
  22. <Window.Resources>
  23. <DataTemplate x:Key="Foo">
  24. <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
  25. <TextBlock x:Name="TextBlock" Text="Hover over" />
  26. <wpfApp1:MyPopup PlacementTarget="{Binding ElementName=TextBlock}" />
  27. </StackPanel>
  28. </DataTemplate>
  29. </Window.Resources>
  30. <ListBox ItemTemplate="{StaticResource Foo}" ItemsSource="{Binding MyList}" />
  31.  
  32. public partial class MainWindow
  33. {
  34. public MainWindow()
  35. {
  36. InitializeComponent();
  37. MyList = new List<string>{"Dan","John","Test"};
  38. DataContext = this;
  39. }
  40. public List<string> MyList { get; }
  41. }
Add Comment
Please, Sign In to add comment