2
我有一個自定義按鈕,其中包含一個自動收報器符號和圖像。一切都按照我需要的方式工作,除了我想單擊按鈕時的小工具。整個按鈕(光標手)顯示是否將鼠標懸停在不包含文本框的按鈕的任何部分(包括圖像)上。因此點擊股票代碼(十字線顯示的不是手形光標)不會執行我的命令。我錯過了一些愚蠢的東西,我不能把手指放在它上面。任何幫助將不勝感激。這是從我的資源字典:使用的,而不是一個TextBox TextBlock的WPF自定義按鈕,圖像和文字無法在文本塊上單擊
<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>
OMG,我知道這是愚蠢的東西我在做什麼。這解決了它。謝謝!!! – SMULLER
如果您提出的問題不會將您的所有XAML 僅僅是與讀者相關的部分。 沒有人關心你的對齊和顏色和東西, ,並注意到你在標題中編寫了TextBlock而不是TextBox。 –