簡體   English   中英

MahApps DataGridCell樣式

[英]MahApps DataGridCell style

我在我的應用程序中使用MahApps庫,默認樣式的datagrid單元格沒有邊框:

無邊界的數據網格單元

但我希望DataGrid看起來像這樣:

帶有邊界的數據網格單元

所以我開始:

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Height"
            Value="33" />
    <Setter Property="Background"
            Value="Transparent" />
    <Setter Property="Padding"
            Value="5,0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border x:Name="border"
                        Background="Transparent"
                        BorderBrush="Black"
                        BorderThickness="1"
                        Padding="0,10,0,10"
                        SnapsToDevicePixels="True">
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Grid Background="{TemplateBinding Background}">
                    <ContentPresenter VerticalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

但沒有任何變化,因此我假設我缺少基於[=}屬性,但是我不知道如何,我已經尋求幫助MathApps團隊,但沒有幫助...

DataGrid控件本身上設置GridLinesVisibility="All"將為您提供內部邊框。

在此處輸入圖片說明

請注意,它仍然不能為您提供外部邊界,但是比編輯默認模板要容易得多。

如果您確實想獲得外部邊界,則需要覆蓋默認模板。

MahApps的默認DataGridCell模板密鑰是MetroDataGridCell ,因此您需要使用<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM