WPF:链接另一个控件';某些控件中的s属性';扳机
这是我的文本块WPF:链接另一个控件';某些控件中的s属性';扳机,wpf,xaml,triggers,styles,Wpf,Xaml,Triggers,Styles,这是我的文本块 <Image x:Name:imgAnother/> <TextBlock> this is my text block <TextBlock.Style> <Style TargetType="TextBlock"> <Setter Property="TextDecorations" Value="None"/>
<Image x:Name:imgAnother/>
<TextBlock>
this is my text block
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="TextDecorations" Value="None"/>
<Style.Triggers>
<Trigger Property="TextBlock.IsMouseOver" Value="True">
<Setter Property="Foreground" Value="RoyalBlue"/>
<!--I like to insert a code at here that changes another control's property...-->
</Trigger>
<Trigger Property="TextBlock.IsMouseOver" Value="False">
<Setter Property="Foreground" Value="#FF808080"/>
<!--..and this line too.-->
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
这是我的文本块
我喜欢编写一个xaml代码,它可以更改另一个控件的权限,比如“imgAnother”
我该怎么做呢?您必须以某种方式聚合源和目标 您可以创建包含超链接/文本块和图像的自定义控件。如果在这样的示例中有多个行为的块,那么这是首选方法 如果你不喜欢这个。您可以创建“临时”匿名控件,如下所示:
<ControlTemplate x:Key="myCtl" TargetType="ContentControl">
<StackPanel>
<Image x:Name="img"/>
<ContentPresenter x:Name="ctr" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger SourceName="ctr" Property="IsMouseOver" Value="True">
<Setter TargetName="ctr" Property="Foreground" Value="RoyalBlue"/>
<!--I like to insert a code at here that changes another control's property...-->
</Trigger>
<Trigger SourceName="ctr" Property="IsMouseOver" Value="False">
<Setter TargetName="ctr" Property="Foreground" Value="#FF808080"/>
<!--..and this line too.-->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
上述xaml将驻留在窗口的资源中
注意:它更像是一个要遵循的轨迹,而不是一个功能齐全的片段
在正文中,您可以以下列方式引用控件:
<ContentControl Template="{StaticResource myCtl}" Content="this is my text block" />
希望能有所帮助。图像(或控件)在哪里?基本上,我想在同一窗口中更改另一个控件的属性。而且,控件也可以放在应用程序资源、窗口资源、控件资源中。