डेटा प्रविष्टि फ़ॉर्म को स्टाइल करने के लिए नीचे कुछ लिखना असामान्य नहीं है, लेकिन मेरी समस्या यह है कि TextBox
और TextBlock
BaseElementStyle
में स्थित सेटर्स को लागू करने के लिए प्रतीत नहीं होता है। आम तौर पर मुझे उन्हें अलग से परिभाषित करने की आवश्यकता होती है।मेरा टेक्स्टब्लॉक/टेक्स्टबॉक्स क्यों बेस स्टाइल से मूल्य लागू नहीं करता है?
यह क्यों है? और क्या इसके चारों ओर एक रास्ता है?
मैं इसे इस तथ्य वे आम तौर पर अन्य नियंत्रण टेम्पलेट्स में उपयोग किया जाता (उदाहरण के लिए TextBlock सबसे नियंत्रण में प्रयोग किया जाता है और पाठबॉक्स Datepickers में प्रयोग किया जाता है और comboboxes)
<Style x:Key="BaseElementStyle" TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="5" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource BaseElementStyle}" />
धन्यवाद! और आपने मुझे कुछ नया सिखाया ... मुझे पता नहीं था कि आप एक अंतर्निहित शैली पर एक शैली का आधार बना सकते हैं जैसे कि आप # 2 में दिखाते हैं। जानना बहुत अच्छा है! – Rachel