Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class CarInfo : DependencyObject
  2. {
  3. public static readonly DependencyProperty MaxSpeedProperty =
  4. DependencyProperty.Register("MaxSpeed", typeof (double), typeof (CarInfo), new PropertyMetadata(0.0));
  5.  
  6. public double MaxSpeed
  7. {
  8. get { return (double) GetValue(MaxSpeedProperty); }
  9. set { SetValue(MaxSpeedProperty, value); }
  10. }
  11. }
  12.  
  13. public class Car : DependencyObject
  14. {
  15.  
  16. public static readonly DependencyProperty InfoProperty =
  17. DependencyProperty.Register("Info", typeof (CarInfo), typeof (Car), new PropertyMetadata(null));
  18.  
  19. public CarInfo Info
  20. {
  21. get { return (CarInfo) GetValue(InfoProperty); }
  22. set { SetValue(InfoProperty, value); }
  23. }
  24.  
  25. }
  26.  
  27. <Style TargetType="assembly:Car">
  28. <Setter Property="Template">
  29. <Setter.Value>
  30. <ControlTemplate TargetType="assembly:Car">
  31. <Grid >
  32. !--> <TextBlock Text="{Binding Path=MaxSpeed}" />
  33. </Grid>
  34. </ControlTemplate>
  35. </Setter.Value>
  36. </Setter>
  37. </Style>
  38.  
  39. <TextBlock Text="{Binding Path=Info.MaxSpeed}" />
  40.  
  41. <TextBlock Text="{Binding Path=Info.MaxSpeed, RelativeSource={RelativeSource TemplatedParent}}" />
  42.  
  43. <TextBlock Text="{Binding Path=Info.MaxSpeed}" />
  44.  
  45. <TextBlock Text="{Binding Path=Info.MaxSpeed, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
  46.  
  47. Car.Info = new CarInfo { MaxSpeed = 100.0 };
Add Comment
Please, Sign In to add comment