我有一个自定义按钮,其中包含一个自动收报机代码和一个图像。当我想点击按钮时,除了onMouseover之外,一切都正常工作。整个按钮(光标指针)显示我是否鼠标悬停在不包含文本框的按钮(包括图像)的任何部分。因此,单击股票代码(十字准线显示不是手形光标)不会执行我的命令。我错过了一些愚蠢的东西,我只是不能把手指放在上面。任何帮助将不胜感激。这来自我的资源词典:
<Style x:Key="TickerButtonStyle2" TargetType="{x:Type Controls:DataGridCell}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Button>
<Button.Resources>
<Style TargetType="Button">
<Setter Property="Command" Value="{Binding SwitchViewCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type local:MainView}}}" />
<Setter Property="CommandParameter" Value="{Binding Ticker}"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="bd" BorderBrush="Transparent"
BorderThickness="0"
Margin="0"
Background="Transparent">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Background="Transparent">
<TextBox Name="txt" IsReadOnly="True"
BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
TextAlignment="Left"
Foreground="White"
FontFamily="Ariel"
FontSize="12"
Text="{Binding Path=Ticker, Converter={StaticResource tickerSymbolDisplay}}"
/>
<Image Width="16" Height="11" Stretch="Fill" Source="{Binding Path=Ticker, Converter={StaticResource tickerImageDisplay}}" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="bd" Property="Background" Value="Transparent"/>
<Setter TargetName="txt" Property="Foreground" Value="#FF7E00"/>
<Setter Property="ToolTip" Value="View Fundamentals"/>
</Trigger>
<Trigger Property="Button.IsPressed" Value="true">
<Setter TargetName="bd" Property="Background" Value="Transparent"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Resources>
</Button>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:1)
尝试使用TextBlock而不是TextBox:
<TextBlock Name="txt"
Background="Transparent"
TextAlignment="Left"
Foreground="White"
FontFamily="Ariel"
FontSize="12"
Text="ticker"
Text="{Binding Path=Ticker, Converter={StaticResource tickerSymbolDisplay}}"
/>