• WPF DataGridTemplateColumn


    DataGridTemplateColumn自定义单元格样式

    <DataGrid Grid.Row="0" Name="BasicRuleDataGrid" PreviewMouseWheel="BasicRuleDataGrid_OnPreviewMouseWheel"                 
                           VerticalScrollBarVisibility="Auto"
                           HorizontalScrollBarVisibility="Auto"
                           AutoGenerateColumns="False"
                           RowDetailsVisibilityMode="VisibleWhenSelected"
                           SnapsToDevicePixels="True"
                           EnableRowVirtualization="False"
                           AreRowDetailsFrozen="False"
                           SelectionMode="Single"                     
                           ScrollViewer.IsDeferredScrollingEnabled="True"
                           IsReadOnly="True"
                           ItemsSource="{Binding ElementName=ComRuleMDataGrid, Path=SelectedItem.BasicRulesBinding}"  
                            >
        <!--上方:需要告知在ComRuleMDataGrid(子)里面找,在VM(父)里面找找不到-->
        <DataGrid.AlternatingRowBackground>
            <SolidColorBrush Color="#EBF7FC"></SolidColorBrush>
        </DataGrid.AlternatingRowBackground>
        <!--列-->
        <DataGrid.Columns>
            <DataGridTextColumn Width="*" Header="基本规则名称" Binding="{Binding BasRuleNameBinding}" />
            <DataGridTextColumn Width="*" Header="基本规则说明" Binding="{Binding CommentBinding}" />
            <DataGridTemplateColumn Header="是否删除" Width="Auto">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button HorizontalAlignment="Center" Tag="{Binding}" Style="{StaticResource BtADDStyle}" Content="-" Click="ButtonListDelet_OnClick_BasicRule"></Button>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
    

    列表说明:
    数据源ItemsSource绑定类的collection
    选择项SelectedItem绑定类的一个对象(便于后台操作,自动)
    显示绑定类中某一属性

  • 相关阅读:
    secFox setting
    Xmind settings lower
    Test435678
    Cmd管理员运行
    office install problems
    MSOCache office问题
    WeRun is mini-app
    解决谷歌跨域调试不可用
    xml文件读写
    c++ 矩阵运算库 Eigen等
  • 原文地址:https://www.cnblogs.com/Lulus/p/8158351.html
Copyright © 2020-2023  润新知