C# 从资源中触发资源上的触发器
是否可以从其他资源更改资源。如果鼠标位于StartButtonMain上,我喜欢更改StartButtonRed的背景C# 从资源中触发资源上的触发器,c#,wpf,C#,Wpf,是否可以从其他资源更改资源。如果鼠标位于StartButtonMain上,我喜欢更改StartButtonRed的背景 <ImageBrush x:Key="RedBackgroundActive" ImageSource="/Images/start_red_active.png" Stretch="Fill"/> <Style x:Key="StartButtonMain" TargetType="{x:Type local:SimpleButton}">
<ImageBrush x:Key="RedBackgroundActive" ImageSource="/Images/start_red_active.png" Stretch="Fill"/>
<Style x:Key="StartButtonMain" TargetType="{x:Type local:SimpleButton}">
<Style.Resources>
<ImageBrush x:Key="MainBackground" ImageSource="/Images/start_main_normal.png" Stretch="Fill"/>
<ImageBrush x:Key="MainBackgroundActive" ImageSource="/Images/start_main_active.png" Stretch="Fill"/>
</Style.Resources>
<Style.Setters>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="{StaticResource MainBackground}"/>
<Setter Property="Visibility" Value="Visible"/>
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource MainBackgroundActive}"/>
// Change the background of StartButtonRed to RedBackgroundActive
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="StartButtonRed" TargetType="{x:Type local:SimpleButton}">
<Style.Resources>
<ImageBrush x:Key="RedBackground" ImageSource="/Images/start_red_normal.png" Stretch="Fill"/>
</Style.Resources>
<Style.Setters>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="{StaticResource RedBackground}"/>
<Setter Property="Visibility" Value="Visible"/>
</Style.Setters>
</Style>
//将StartButtonRed的背景更改为RedBackgroundActive
你不能这样做。由于样式是资源,并且触发器只能从其自己的模板中或使用绑定到其他实际框架元素的方式将框架元素作为目标,因此不能绑定到其他资源
你可以用解决这个问题。你不能这样做。由于样式是资源,并且触发器只能从其自己的模板中或使用绑定到其他实际框架元素的方式将框架元素作为目标,因此不能绑定到其他资源
你可以用。我不确定这是否正是你想要的,但请检查:,具体检查名为“扩展样式”的部分和
BasedOn
属性。@Coding Gorilla否,但知道BasedOn属性很好。我不确定这是否正是你想要的,但请检查:,具体查看名为“扩展样式”的部分和BasedOn
属性。@Coding Gorilla否,但了解BasedOn属性很好。