我已將自定義樣式應(yīng)用于 DataGrid 的列標(biāo)題。這是它的簡化版本:<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="DataGridColumnHeader"> <Grid> <Border BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> <Grid> <StackPanel Orientation="Horizontal"> <ContentPresenter Margin="5 0 5 0" HorizontalAlignment="Center" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <Image IsHitTestVisible="True" Source="pin.png"> <Image.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{x:Static myView:MyCommand}" CommandParameter="{Binding}" /> </Image.InputBindings> </Image> </StackPanel> </Grid> </Border> <Thumb x:Name="PART_LeftHeaderGripper" Style="{StaticResource DataGridColumnHeaderResizeThumb}"/> <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource DataGridColumnHeaderResizeThumb}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter></Style>單擊圖像時(shí),我正在努力使命令觸發(fā)。有什么我想念的嗎?單擊 DataGridColumnHeader 中的元素(即圖像)時(shí),是否有不同的方式可以觸發(fā)命令?更多細(xì)節(jié):MyCommand 是在 Window 的 CommandBindings 中定義的。我沒有在此處包含此代碼。我為其他工作正常的元素(即 DataGridCell)定義了類似的其他命令。似乎有一些特定于 DataGridColumnHeader 元素阻止命令被觸發(fā)的方式。
1 回答

楊__羊羊
TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
似乎您綁定到MyCommand
xmlns 下的類型myView
;相反,您應(yīng)該綁定到MyCommand
(假設(shè)類MyCommand
實(shí)現(xiàn)ICommand
)的實(shí)例。你可以考慮在這里實(shí)現(xiàn)單例。或者您可以定義MyCommand
任何地方的靜態(tài)實(shí)例。
- 1 回答
- 0 關(guān)注
- 159 瀏覽
添加回答
舉報(bào)
0/150
提交
取消