我有一个UserControl
:
<UserControl x:Class="WpfApplication1.UserControl1"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Button Name="myButton" Content="hello world" Padding="10" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</UserControl>
和代码隐藏:
public partial class UserControl1 : UserControl
{
public bool IsShown
{
get { return (bool)GetValue(IsShownProperty); }
set { SetValue(IsShownProperty, value); }
}
public static readonly DependencyProperty IsShownProperty =
DependencyProperty.Register("IsShown", typeof(bool), typeof(UserControl1), new UIPropertyMetadata(false));
public UserControl1()
{
InitializeComponent();
}
}
当 IsShown 为 true 时,我想向myButton 添加一个 Effect 。在主窗口中,
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication1">
<Window.Resources>
<DropShadowEffect x:Key="outerGlow" Color="#00E300" Direction="0" ShadowDepth="0" BlurRadius="12" />
<Style x:Key="style" TargetType="my:UserControl1">
<Style.Triggers>
<Trigger Property="IsShown" Value="true">
<Setter Property="myButton.Effect" Value="{StaticResource outerGlow}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<my:UserControl1 x:Name="userControl11" Style="{StaticResource style}" />
</Window>
但是 VS 无法解决 symbol myButton
。
如何解决?
更新:
我找到了 MSDN 文章。谁能告诉我我的财产路径属于哪一类?