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