Guest User

Untitled

a guest
Aug 17th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. Binding OnwayToSource not working as expected - what alternatives?
  2. <DataTemplate DataType="{x:Type p:Fish}">
  3. <Border BorderBrush="Black" BorderThickness="2" >
  4. <TextBlock FontSize="14" TextAlignment="Center" VerticalAlignment="Center"
  5. Width="{Binding Path=width, Mode=OneWayToSource}"
  6. Height="{Binding Path=height, Mode=OneWayToSource}" ...
  7.  
  8. class Fish {
  9. public double width { get; set; } // From DataTemplate TextBlock.Width.
  10. public double height { get; set; } // From DataTemplate TextBlock.Height
  11. }
  12.  
  13. ...
  14. double rendered_width = my_fish.width; // Use the rendered width!
  15.  
  16. <TextBlock ...
  17. SizeObserver.Observe="True"
  18. SizeObserver.ObservedWidth="{Binding Width, Mode=OneWayToSource}"
  19. SizeObserver.ObservedHeight="{Binding Height, Mode=OneWayToSource}"
  20.  
  21. <StackPanel Orientation="Vertical">
  22. <Border BorderThickness="1" BorderBrush="Red">
  23. <TextBlock Name="tbwidthA" Text="{Binding Path=Howdy}" HorizontalAlignment="Left" Width="200"/>
  24. </Border>
  25. <TextBlock Name="tbwidthAw" Text="{Binding ElementName=tbwidthA, Path=Width}" HorizontalAlignment="Left"/>
  26. <TextBlock Name="tbwidthAaw" Text="{Binding ElementName=tbwidthA, Path=ActualWidth}" HorizontalAlignment="Left" />
  27. <Border BorderThickness="1" BorderBrush="Red">
  28. <TextBlock Name="tbwidthB" Text="{Binding Path=Howdy}" HorizontalAlignment="Left" />
  29. </Border>
  30. <TextBlock Name="tbwidthBw" Text="{Binding ElementName=tbwidthB, Path=Width}" HorizontalAlignment="Left" />
  31. <TextBlock Name="tbwidthAbw" Text="{Binding ElementName=tbwidthB, Path=ActualWidth}" HorizontalAlignment="Left" />
  32. <Button Content="TBwidth" Click="Button_Click_1" Width="60" HorizontalAlignment="Left" />
  33. </StackPanel>
  34.  
  35. Debug.WriteLine(tbwidthB.Width.ToString());
  36. Debug.WriteLine(tbwidthB.ActualWidth.ToString());
Add Comment
Please, Sign In to add comment