में स्टाइल मानों को ओवरराइड करने का उचित तरीका मैं WPF में DataGrid
की सेल शैली संपादित करना चाहता हूं। तो अभिव्यक्ति मिश्रण का उपयोग करते हुए मैं सही करने के लिए जाने - वस्तुओं और समय >> डेटा ग्रिड >> अतिरिक्त टेम्पलेट्स संपादित करें >> संपादित CellStyle >> एक कॉपी संपादित करें
यहाँ क्या पृष्ठ पर दिखाई देता है:WPF
<SolidColorBrush x:Key="{x:Static DataGrid.FocusBorderBrushKey}" Color="#FF000000"/>
<Style x:Key="DataGridCellStyle1" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>
लेकिन मैं केवल चाहते हैं पैडिंग और पृष्ठभूमि को बदलने के लिए। इसके बजाय उसने मुझे सेल टेम्पलेट समेत कोड की 25 लाइनें दी हैं! क्या मुझे कुछ याद आ रहा है, क्या इस तरह के सामानों को स्टाइल करने का एक बेहतर तरीका है जब मैं केवल दो आइटम बदलना चाहता हूं तो इतना अतिरिक्त अनावश्यक कोड लाए बिना?
बहुत बढ़िया सुविधा: HorizontalContentAlignment संपत्ति ओवरराइड करता है। मुझे प्लगइन डीएलएस का उपयोग करने में मदद मिली, बिना मेरी काम की एक टन मुझे बचाने के लिए। धन्यवाद! –