我遇到了一個問題,其中路徑內容的按鈕只檢測鼠標點擊的路徑。我希望爲ux在按鈕的任何位置註冊點擊。我已將按鈕的背景設置爲null和透明,所以頂部控件容器指定背景樣式。如何擊中無效或透明背景上的檢測?
下面是另一個SO後:Mouse event on transparent background
如前所述我都試過透明和空爲止。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wpfMyCustomControl">
<ControlTemplate x:Key="IconTemplate" TargetType="{x:Type ContentControl}">
<Grid>
<Path Name="ForegroundSymbol" Data="M0,0 L1,0 1,1 0,1 0.5,0.5 z" Fill="{TemplateBinding Foreground}" Stretch="Fill" />
</Grid>
</ControlTemplate>
<Style x:Key="IconButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Grid>
<ContentControl Name="icon" Template="{StaticResource IconTemplate}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="MyCustomTemplate" TargetType="{x:Type local:MyCustomControl}">
<Grid Name="LayoutRoot" Background="Red">
<RepeatButton Background="{x:Null}" Style="{StaticResource ResourceKey=IconButtonStyle}" />
</Grid>
</ControlTemplate>
<Style TargetType="{x:Type local:MyCustomControl}">
<Setter Property="Template" Value="{StaticResource ResourceKey=MyCustomTemplate}" />
</Style>
</ResourceDictionary>
如果我從「樣式」中刪除「x:Key」屬性,控件呈現。我已經能夠重現這個問題,使用上面的xaml控件樣式,點擊檢測不會在按鈕的「背景」部分觸發。
如果你提供了一些代碼給我們看,會有很大的幫助。 – JerKimball 2013-03-02 00:51:55
'iconstyle'如何?任何問題都可能與控制模板的「VisualTree」一致。 – JerKimball 2013-03-02 02:56:12
我無法用按鈕,您的''和按鈕的{{:Null}'背景來重現此操作。這證明這是你造成這種情況的'Style'。開始解構風格,直到問題消失,或者以其他方式開始:從空白樣式開始,添加東西,直到問題出現。無論哪種方式,你會發現究竟是什麼導致問題,並反過來將使您能夠解決問題。 –
2013-03-04 07:12:58