亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

單擊數據網格列標題中的元素

單擊數據網格列標題中的元素

C#
慕森王 2021-10-23 16:10:02
我已將自定義樣式應用于 DataGrid 的列標題。這是它的簡化版本:<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>單擊圖像時,我正在努力使命令觸發。有什么我想念的嗎?單擊 DataGridColumnHeader 中的元素(即圖像)時,是否有不同的方式可以觸發命令?更多細節:MyCommand 是在 Window 的 CommandBindings 中定義的。我沒有在此處包含此代碼。我為其他工作正常的元素(即 DataGridCell)定義了類似的其他命令。似乎有一些特定于 DataGridColumnHeader 元素阻止命令被觸發的方式。
查看完整描述

1 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

似乎您綁定到MyCommandxmlns 下的類型myView;相反,您應該綁定到MyCommand(假設類MyCommand實現ICommand)的實例。你可以考慮在這里實現單例?;蛘吣梢远xMyCommand任何地方的靜態實例。


查看完整回答
反對 回復 2021-10-23
  • 1 回答
  • 0 關注
  • 165 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號