0
我想要做的是当我点击一个页面内的按钮“testButton”来触发一个窗口内的边框内的事件。MainWindow内部的资源。如果我从EventTrigger中删除SourceName =“testButton”,它将与每个按钮一起工作,我想要的只是使用该特定按钮。访问WPF中的EventTrigger上的另一个类的按钮(XAML)
<Window x:Class="test.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"
xmlns:local="clr-namespace:test"
mc:Ignorable="d">
<Window.Resources>
<Style TargetType="{x:Type local:mainWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Padding="5">
<Border.Background>
<SolidColorBrush x:Name="bgBrush" Color="Transparent" />
</Border.Background>
<Border.Triggers>
<EventTrigger RoutedEvent="Button.Click" SourceName="testButton">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="bgBrush"
Storyboard.TargetProperty = "Color"
From="Transparent"
To = "White"
Duration="0:0:01.00"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
</Window>
这里是页的按钮是:
<Page x:Class="test.testPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:test"
mc:Ignorable="d" Width="300" Height="200">
<Grid>
<Button x:Name="testButton" Height="20" Width="50" Content="Test"/>
</Grid>
</Page>
这是一个基于MMVM的应用程序还是正常? – Ramankingdom
我不知道区别,我是新来的整个XAML的东西。 – Toody
然后你可能会尝试更多的进步。随着基础知识将帮助你很多。阅读事件触发器并尝试在主窗口内直接启动。 – Ramankingdom