2012-06-29 10 views
9

मैं एक निश्चित प्रकार के तत्वों के लिए एक और शैली लागू करने के लिए शैली प्राप्त करने की कोशिश कर रहा हूं। सीएसएस जहां आप क्या करेंगेडब्ल्यूपीएफ - एक शैली कैसे बनाएं जो शैलियों को बच्चों के प्रकारों पर लागू करे

div a 
{ 
    background-color:red; 
} 

सभी < एक > तत्वों कि <div> तत्वों द्वारा निहित हैं करने के लिए एक लाल रंग की पृष्ठभूमि को लागू करने के लिए इसी तरह की।

विशेष रूप से, मैं एक टेबल शैली समूह के भीतर मौजूद सभी टेबलकल्स को अपनी सीमाओं को बदलने के लिए एक निश्चित शैली के साथ निहित करने की कोशिश कर रहा हूं।

मेरे पास निम्न समाधान है जहां प्रत्येक सेल शैली अलग-अलग सेट की जाती है।

<Table> 
    <Table.Columns> 
     <TableColumn/> 
     <TableColumn/> 
    </Table.Columns> 

    <Table.Resources> 
     <Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}"> 
      <Setter Property="FontWeight" Value="Normal"/> 
      <Setter Property="FontSize" Value="12"/> 
     </Style> 

     <Style x:Key="HeaderCellStyle" TargetType="{x:Type TableCell}"> 
      <Setter Property="BorderThickness" Value="0,1,0,1" /> 
      <Setter Property="BorderBrush" Value="Black" /> 
     </Style> 
    </Table.Resources> 

    <TableRowGroup Name="TableColumnHeaders" Style="{StaticResource HeaderStyle}"> 
     <TableRow> 
      <TableCell Style="{StaticResource HeaderCellStyle}"> 
       <Paragraph> 
        Description 
       </Paragraph> 
      </TableCell> 
      <TableCell Style="{StaticResource HeaderCellStyle}"> 
       <Paragraph> 
        Amount 
       </Paragraph> 
      </TableCell> 
     </TableRow> 
    </TableRowGroup> 
</Table> 

यह स्पष्ट रूप से प्राथमिकता नहीं दी के रूप में यह XAML जब वहाँ कई कोशिकाओं हैं bloats है।

मैंने बिना किसी सफलता के निम्नलिखित प्रयास किए हैं।

<Table.Resources> 
    <Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}"> 
     <Style.Resources> 
      <Style TargetType="{x:Type TableCell}"> 
       <Setter Property="BorderThickness" Value="0,1,0,1" /> 
       <Setter Property="BorderBrush" Value="Black" /> 
      </Style> 
     </Style.Resources> 
     <Setter Property="FontWeight" Value="Normal"/> 
     <Setter Property="FontSize" Value="12"/> 
    </Style> 
</Table.Resources> 

यह भी किसी कारण से काम नहीं करता है, हालांकि वैध

<Table.Resources> 
    <Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}"> 
     <Setter Property="FontWeight" Value="Normal"/> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="TableCell.BorderThickness" Value="0,1,0,1" /> 
     <Setter Property="TableCell.BorderBrush" Value="Black" /> 
    </Style> 
</Table.Resources> 

वहाँ अपने स्वयं के सेल शैली के साथ कुछ पंक्ति समूहों प्रत्येक और प्रत्येक युक्त कई कोशिकाओं होने जा रहा है। कृपया मुझे बताएं कि एक बेहतर तरीका है।

उत्तर

7

अद्यतन अपनी टिप्पणी

अपनी टिप्पणी के आधार पर पर आधारित है, मेरा मानना ​​है कि आपकी समस्या को आसानी से Style वंशानुक्रम का उपयोग हल हो सकता है।

<Table> 
    <Table.Resources> 

     <Style x:Key="HeaderCellStyle" TargetType="{x:Type TableCell}"> 
      <Setter Property="BorderThickness" Value="0,1,0,1" /> 
      <Setter Property="BorderBrush" Value="Black" /> 
      <Setter Property="TextAlignment" Value="Center" /> 
      <Setter Property="FontStyle" Value="Italic" /> 
      <Setter Property="Padding" Value="5" /> 
     </Style> 

     <Style x:Key="FooterCellStyle" BasedOn="{StaticResource HeaderCellStyle}" TargetType="{x:Type TableCell}"> 
      <Setter Property="Background" Value="AliceBlue" /> 
      <Setter Property="TextAlignment" Value="Right" /> 
      <Setter Property="FontWeight" Value="Bold" /> 
     </Style> 

     <Style x:Key="HeaderTableRowGroupStyle" TargetType="{x:Type TableRowGroup}"> 
      <Style.Resources> 
       <Style BasedOn="{StaticResource HeaderCellStyle}" TargetType="{x:Type TableCell}" /> 
      </Style.Resources> 
     </Style> 

     <Style x:Key="FooterTableRowGroupStyle" TargetType="{x:Type TableRowGroup}"> 
      <Style.Resources> 
       <Style BasedOn="{StaticResource FooterCellStyle}" TargetType="{x:Type TableCell}" /> 
      </Style.Resources> 
     </Style> 

    </Table.Resources> 
    <Table.Columns> 
     <TableColumn /> 
     <TableColumn /> 
     <TableColumn /> 
     <TableColumn /> 
    </Table.Columns> 

    <!-- This TableRowGroup hosts a header row for the table. --> 
    <TableRowGroup Style="{StaticResource HeaderTableRowGroupStyle}"> 
     <TableRow> 
      <TableCell /> 
      <TableCell> 
       <Paragraph>Gizmos</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>Thingamajigs</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>Doohickies</Paragraph> 
      </TableCell> 
     </TableRow> 
    </TableRowGroup> 

    <!-- This TableRowGroup hosts the main data rows for the table. --> 
    <TableRowGroup> 
     <TableRow> 
      <TableCell> 
       <Paragraph>Blue</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>1</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>2</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>3</Paragraph> 
      </TableCell> 
     </TableRow> 
     <TableRow> 
      <TableCell> 
       <Paragraph>Red</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>1</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>2</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>3</Paragraph> 
      </TableCell> 
     </TableRow> 
     <TableRow> 
      <TableCell> 
       <Paragraph>Green</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>1</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>2</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>3</Paragraph> 
      </TableCell> 
     </TableRow> 
    </TableRowGroup> 

    <!-- This TableRowGroup hosts a footer row for the table. --> 
    <TableRowGroup Style="{StaticResource FooterTableRowGroupStyle}"> 
     <TableRow> 
      <TableCell> 
       <Paragraph>Totals</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>3</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>6</Paragraph> 
      </TableCell> 
      <TableCell> 
       <Paragraph>9</Paragraph> 
      </TableCell> 
     </TableRow> 
    </TableRowGroup> 
</Table> 

जब भी आप एक सामान्य Style कि एक खास प्रकार के तत्वों को लक्षित करेगा परिभाषित करना चाहते हैं, तो आप उस शैली के लिए एक कुंजी उल्लेख नहीं होना चाहिए: नीचे विभिन्न TableRowGroups पर 2 अलग सेल शैलियाँ का उपयोग करने का एक उदाहरण है । एक्स को हटाने का प्रयास करें: स्टाइल से कुंजी और सबकुछ ठीक से काम करना चाहिए, जैसे:

<Table.Resources> 
    <Style TargetType="{x:Type TableRowGroup}"> 
     <Setter Property="FontWeight" Value="Normal"/> 
     <Setter Property="FontSize" Value="12"/> 
     <Setter Property="TableCell.BorderThickness" Value="0,1,0,1" /> 
     <Setter Property="TableCell.BorderBrush" Value="Black" /> 
    </Style> 
</Table.Resources> 
+0

मुझे पता है कि x: मुख्य विशेषता कैसे काम करती है; आपका उदाहरण या तो काम नहीं करता है। ध्यान दें कि मेरे उदाहरण में मैं विशिष्ट पंक्ति समूहों में "हेडर स्टाइल" लागू कर रहा था (क्योंकि मैं नहीं चाहता कि सभी टेबल पंक्ति समूहों को यह शैली हो) ताकि शैली अभी भी ठीक से लागू हो रही हो। – Slight

संबंधित मुद्दे