This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [TestFixture] | |
| public class LetsCheckTheEventHandlers | |
| { | |
| [Test] | |
| public void ChainedEventHandlers() | |
| { | |
| var m = new MultiplyByTwo(); | |
| var s = new CreateResultStars(m); | |
| Assert.AreEqual(string.Empty, s.Stars); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Window x:Class="Z10_BindingFromCode.MainWindow" | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
| mc:Ignorable="d" | |
| Title="MainWindow" Height="350" Width="525"> | |
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="*"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Button x:Name="UpdateLabelButton" Grid.Row="1" Grid.Column="1">Update Label</Button> | |
| <TextBlock x:Name="UpdatedLabel" Grid.Row="3" Grid.Column="1">Old Label Value</TextBlock> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static DependencyProperty LabelDataProperty = DependencyProperty.Register(nameof(LabelData), typeof(string), typeof(MainWindow), new PropertyMetadata("Old Label Value")); | |
| public string LabelData | |
| { | |
| get { return (string)GetValue(LabelDataProperty); } | |
| set { SetValue(LabelDataProperty, value); } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var binding = new Binding(nameof(LabelData)) { Source = this, Mode = BindingMode.OneWay }; | |
| BindingOperations.SetBinding(UpdatedLabel, TextBlock.TextProperty, binding); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LeftRightLayoutControl : StackPanel | |
| { | |
| private Grid _grid; | |
| private StackPanel _left; | |
| private StackPanel _right; | |
| public LeftRightLayoutControl() | |
| { | |
| _grid = new Grid(); | |
| _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum Side | |
| { | |
| None, | |
| Left, | |
| Right | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static readonly DependencyProperty SideProperty = DependencyProperty.RegisterAttached(nameof(Side), typeof(Side), typeof(LeftRightLayoutControl), new PropertyMetadata(Side.None, UpdateSide)); | |
| public static Side GetSide(UIElement target) | |
| { | |
| return (Side)target.GetValue(SideProperty); | |
| } | |
| public static void SetSide(UIElement target, Side value) | |
| { | |
| target.SetValue(SideProperty, value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void UpdateSide(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
| { | |
| var obj = (FrameworkElement)d; | |
| // Finding the LeftRightLayoutControl to which this object belongs to either directly or indirectly. | |
| var parent = LogicalTreeHelper.GetParent(obj); | |
| while (parent != null && parent.GetType() != typeof(LeftRightLayoutControl)) | |
| { | |
| parent = LogicalTreeHelper.GetParent(parent); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <local:LeftRightLayoutControl> | |
| <Button local:LeftRightLayoutControl.Side="Left">On the left</Button> | |
| <Button local:LeftRightLayoutControl.Side="Right">On the right</Button> | |
| <Button local:LeftRightLayoutControl.Side="Left">On the left again</Button> | |
| </local:LeftRightLayoutControl> |