本文整理汇总了C#中System.Windows.Controls.Control.RaiseEvent方法的典型用法代码示例。如果您正苦于以下问题:C# Control.RaiseEvent方法的具体用法?C# Control.RaiseEvent怎么用?C# Control.RaiseEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Control
的用法示例。
在下文中一共展示了Control.RaiseEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendKeyDownEvent
/// <summary>
/// Emulates a keydown event, as if "key" were pressed when the "target" control has focus.
/// </summary>
/// <param name="target">Control to send keyDown event to.</param>
/// <param name="key">Key press to emulate in KeyDown event.</param>
private void SendKeyDownEvent(Control target, Key key)
{
var routedEvent = Keyboard.KeyDownEvent; // Event to send
target.RaiseEvent(
new KeyEventArgs(
Keyboard.PrimaryDevice,
PresentationSource.FromVisual(target),
0,
key) { RoutedEvent = routedEvent }
);
}
示例2: TemplateApplyTest
public void TemplateApplyTest()
{
string text = @"
<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='root'>
<FrameworkElement x:Name='child' Height='400'/>
<ControlTemplate.Triggers>
<Trigger Property='FrameworkElement.Width' Value='100'>
<Setter Property='FrameworkElement.Height' Value='100'/>
</Trigger>
<Trigger Property='FrameworkElement.Width' Value='200'>
<Setter Property='FrameworkElement.Height' Value='200'/>
<Setter TargetName='child' Property='FrameworkElement.Height' Value='200'/>
</Trigger>
<EventTrigger RoutedEvent='FrameworkElement.Initialized'>
<Setter Property='FrameworkElement.Height' Value='300'/>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>";
ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate;
Control control = new Control();
control.Width = 100;
control.Template = controlTemplate;
control.ApplyTemplate();
Assert.AreEqual(1, control.VisualChildren.Count());
FrameworkElement child1 = control.TemplateChild as FrameworkElement;
Assert.IsNotNull(child1);
FrameworkElement child2 = control.Template.FindName("child", control) as FrameworkElement;
Assert.AreEqual(child1, child2);
Assert.AreEqual(control, child1.TemplatedParent);
Assert.AreEqual(400, child1.Height);
Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetBaseValueSource(FrameworkElement.HeightProperty));
Assert.AreEqual(100, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
control.Width = 200;
Assert.AreEqual(200, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
Assert.AreEqual(200, child1.Height);
Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetBaseValueSource(FrameworkElement.HeightProperty));
control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
Assert.AreEqual(300, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
control.Template = null;
control.ApplyTemplate();
Assert.AreEqual(Double.NaN, control.Height);
}
示例3: StyleEventTriggerTest
public void StyleEventTriggerTest()
{
string text = @"
<Style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests'>
<Setter Property='FrameworkElement.Width' Value='100'/>
<EventSetter Event='FrameworkElement.Initialized' Handler='InitializedHandler'/>
<Style.Triggers>
<EventTrigger RoutedEvent='FrameworkElement.Initialized'>
<Setter Property='FrameworkElement.Width' Value='200'/>
</EventTrigger>
</Style.Triggers>
</Style>";
TestStyle style = new TestStyle();
XamlLoader.Load(style, XamlParser.Parse(text));
Control control = new Control();
control.Style = style;
Assert.AreEqual(100, control.Width);
Assert.AreEqual(BaseValueSource.Style, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
Assert.AreEqual(0, style.InitializedHandlerCallsCount);
control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
Assert.AreEqual(200, control.Width);
Assert.AreEqual(BaseValueSource.StyleTrigger, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
Assert.AreEqual(1, style.InitializedHandlerCallsCount);
control.Style = null;
Assert.AreEqual(Double.NaN, control.Width);
Assert.AreEqual(BaseValueSource.Default, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
Assert.AreEqual(Double.NaN, control.Width);
Assert.AreEqual(BaseValueSource.Default, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
Assert.AreEqual(1, style.InitializedHandlerCallsCount);
}