protected virtual void Init() { HostPanel = new UnfocusablePanel(); HostPanel.Click += OnClick; Cursor = Cursors.Default; BorderColor = Color.Silver; BackColor2 = Color.White; BackColor = InnerControl == null ? Color.Silver : SystemColors.Control; ForeColor = Color.Black; TextAlignment = StringAlignment.Near; Font = Range.tb.Parent == null ? Range.tb.Font : Range.tb.Parent.Font; if (InnerControl != null) { HostPanel.Controls.Add(InnerControl); var size = InnerControl.GetPreferredSize(InnerControl.Size); HostPanel.Width = size.Width + 2; HostPanel.Height = size.Height + 2; InnerControl.Dock = DockStyle.Fill; InnerControl.Visible = true; BackColor = SystemColors.Control; } else { HostPanel.Height = Range.tb.CharHeight + 5; } }
public PerformanceTestControl() { var innerControl = new InnerControl(); Center = innerControl; Bottom = new Button("Reset Counter", (sender, args) => innerControl.ResetCounter()); }
public MyControl2() { // We emulate the following XAML code : /* <local:MyControl2> * <local:MyControl2.Template> * <ControlTemplate TargetType="local:MyControl1"> * <Border> * <VisualStateManager.CustomVisualStateManager> * <local:Test_CustomVisualStateManager /> * </VisualStateManager.CustomVisualStateManager> * <VisualStateManager.VisualStateGroups> * <VisualStateGroup x:Name="group1"> * <VisualState x:Name="state1"> * <Storyboard> * <DoubleAnimation Storyboard.TargetName="InnerControl" * Storyboard.TargetProperty="Property1" * Duration="0" * To="42" /> * </Storyboard> * </VisualState> * <VisualState x:Name="state2"> * <Storyboard> * <DoubleAnimation Storyboard.TargetName="InnerControl" * Storyboard.TargetProperty="Property2" * Duration="0" * To="84" /> * </Storyboard> * </VisualState> * </VisualStateGroup> * <VisualStateGroup x:Name="group2"> * <VisualState x:Name="state3"> * <Storyboard> * <DoubleAnimation Storyboard.TargetName="InnerControl" * Storyboard.TargetProperty="Property3" * Duration="0" * To="168" /> * </Storyboard> * </VisualState> * <VisualState x:Name="state4"> * <Storyboard> * <DoubleAnimation Storyboard.TargetName="InnerControl" * Storyboard.TargetProperty="Property4" * Duration="0" * To="336" /> * </Storyboard> * </VisualState> * </VisualStateGroup/> * </VisualStateManager.VisualStateGroups> * <local:InnerControl x:Name="InnerControl" /> * </Border> * </ControlTemplate> * </local:MyControl2.Template> * <local:MyControl2> */ InnerControl = new InnerControl() { Name = "InnerControl" }; // Emulate a template TemplateChild = new Border { Child = InnerControl, }; // Ensure we can find the InnerControl with Control.GetTempleChild(...) RegisterName("InnerControl", InnerControl); VisualStateManager.SetCustomVisualStateManager(TemplateChild, new Test_CustomVisualStateManager()); // 1 - VisualStateGroup 1 var group1 = new VisualStateGroup { Name = "group1" }; // 1.1 - VisualState 1 var state1 = new VisualState { Name = "state1" }; var sb1 = new Storyboard(); var db1 = new DoubleAnimation { Duration = new Duration(TimeSpan.Zero), To = 42d, }; sb1.Children.Add(db1); Storyboard.SetTargetName(db1, "InnerControl"); Storyboard.SetTargetProperty(db1, new PropertyPath(InnerControl.Property1Property)); state1.Storyboard = sb1; // 1.2 - VisualState 2 var state2 = new VisualState { Name = "state2" }; var sb2 = new Storyboard(); var db2 = new DoubleAnimation { Duration = new Duration(TimeSpan.Zero), To = 84d, }; sb2.Children.Add(db2); Storyboard.SetTargetName(db2, "InnerControl"); Storyboard.SetTargetProperty(db2, new PropertyPath(InnerControl.Property2Property)); state2.Storyboard = sb2; group1.States.Add(state1); group1.States.Add(state2); // 2 - VisualStateGroup 2 var group2 = new VisualStateGroup { Name = "group2" }; // 2.1 - VisualState 3 var state3 = new VisualState { Name = "state3" }; var sb3 = new Storyboard(); var db3 = new DoubleAnimation { Duration = new Duration(TimeSpan.Zero), To = 168d, }; sb3.Children.Add(db3); Storyboard.SetTargetName(db3, "InnerControl"); Storyboard.SetTargetProperty(db3, new PropertyPath(InnerControl.Property3Property)); state3.Storyboard = sb3; // 2.2 - VisualState 4 var state4 = new VisualState { Name = "state4" }; var sb4 = new Storyboard(); var db4 = new DoubleAnimation { Duration = new Duration(TimeSpan.Zero), To = 336d, }; sb4.Children.Add(db4); Storyboard.SetTargetName(db4, "InnerControl"); Storyboard.SetTargetProperty(db4, new PropertyPath(InnerControl.Property4Property)); state4.Storyboard = sb4; group2.States.Add(state3); group2.States.Add(state4); // Register VisualStateGroups VisualStateManager.GetVisualStateGroups(TemplateChild).Add(group1); VisualStateManager.GetVisualStateGroups(TemplateChild).Add(group2); }