如何在DataGridCheckBoxColumn中的复选框中添加1像素的上边距?

时间:2013-03-26 23:12:09

标签: wpf wpf-controls wpfdatagrid

如何在DataGridCheckBoxColumn中的复选框中添加1像素的上边距?

2 个答案:

答案 0 :(得分:2)

您可以尝试以下操作:

<DataGrid ItemsSource="{Binding}">
    <DataGrid.Columns>
        <DataGridCheckBoxColumn Header="CheckBox">
            <DataGridCheckBoxColumn.ElementStyle>
                <Style>
                    <Setter Property="FrameworkElement.Margin" Value="0,1,0,0" />
                    <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center" />
                </Style>
            </DataGridCheckBoxColumn.ElementStyle>
        </DataGridCheckBoxColumn>
    </DataGrid.Columns>
</DataGrid>

确实有效, CheckBox 可以获得指定的Margin。请参阅msdn有关ElementStyle属性的文章。此外,如果您在 DataGrid 中启用了修改功能,则可以更改EditingElementStyle,以应用适当的应用程序外观。

答案 1 :(得分:0)

 public string getStyle(string ClassName)
    {
        IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
        return (String)js.ExecuteScript(
        "function getStyle(ClassName) {" +
            "var styleSheets = window.document.styleSheets;" +
            "var styleSheetsLength = styleSheets.length;" +
            "for (var i = 0; i < styleSheetsLength; i++)" +
            "{" +
            "    var classes = styleSheets[i].rules || styleSheets[i].cssRules;" +
            "    if (!classes)" +
            "        continue;" +
            "    var classesLength = classes.length;" +
            "    for (var x = 0; x < classesLength; x++)" +
            "    {" +
            "        if (classes[x].selectorText == ClassName)" +
            "        {" +
            "            var ret;" +
            "            if (classes[x].cssText)" +
            "            {" +
            "                ret = classes[x].cssText;" +
            "            }" +
            "            else" +
            "            {" +
            "                ret = classes[x].style.cssText;" +
            "            }" +
            "            if (ret.indexOf(classes[x].selectorText) == -1)" +
            "            {" +
            "                ret = classes[x].selectorText +   ret  ;" +
            "            }" +
            "            return ret;" +
            "        }" +                
            "    }" +                
            "}" +                
        "}return getStyle(arguments[0]);", ClassName);
    }