2012-12-29 33 views
9

के साथ ग्रिड क्या पृष्ठभूमि छवि और रंग दोनों में xaml में एक संपूर्ण ग्रिड देना संभव है? मैं छवि को स्केल नहीं कर रहा हूं इसलिए ऐसे क्षेत्र हैं जिनमें रंग नहीं है। क्या ग्रिड के बाकी हिस्सों को रंग में रंगना संभव है?पृष्ठभूमि छवि और रंग

यह मेरे वर्तमान कोड है:

<Grid> 
      <Grid.Background> 
       <ImageBrush Stretch="None" ImageSource="Images/background_top.png" AlignmentY="Top" AlignmentX="Center"/> 
      </Grid.Background> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="50*" /> 
      <RowDefinition Height="50*" /> 
     </Grid.RowDefinitions> 
    </Grid> 

उत्तर

0

आप कुछ इस तरह का मतलब:

<Grid Background="Red"> 
     <Grid.Background> 
      <ImageBrush Stretch="None" ImageSource="Images/background_top.png" AlignmentY="Top" AlignmentX="Center"/> 
     </Grid.Background> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="50*" /> 
     <RowDefinition Height="50*" /> 
    </Grid.RowDefinitions> 
</Grid> 
+11

यह काम नहीं करेगा आप पृष्ठभूमि संपत्ति को दो बार सेट कर रहे हैं। –

8

एक ही रास्ता है कि मैं के बारे में सोच सकते हैं पृष्ठभूमि संपत्ति का उपयोग करने के रंग सेट करने के लिए है, तो अपनी सभी पंक्तियों और कॉलमों को विस्तारित करने के लिए ग्रिड में एक छवि जोड़ें। जब तक आपकी ग्रिड में छवि पहली वस्तु है, तब तक दूसरों को शीर्ष पर स्तरित किया जाएगा। मैं आपको वह प्रभाव दूंगा जो आप खोज रहे हैं।

<Grid Background="Red"> 
    <Image Grid.RowSpan="2" Stretch="None" Source="Images/background_top.png" VerticalAlignment="Top" HorizontalAlignment="Center"/> 
    <Label Content="Label" Grid.Row="0" Height="28" HorizontalAlignment="Center" Margin="10,10,0,0" Name="label1" VerticalAlignment="Top" /> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="50*" /> 
     <RowDefinition Height="50*" /> 
    </Grid.RowDefinitions> 
</Grid> 
4

आप ग्रिड के चारों ओर पृष्ठभूमि रंग के रूप में अपने वांछित रंग सेट के साथ सीमा का उपयोग करने का प्रयास कर सकते हैं।

<Border Background="Red"> 
    <Grid> 
     <Grid.Background> 
      <ImageBrush Stretch="None" ImageSource="Images/background_top.png" AlignmentY="Top" AlignmentX="Center"/> 
     </Grid.Background> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="50*" /> 
      <RowDefinition Height="50*" /> 
     </Grid.RowDefinitions> 
    </Grid> 
</Border> 
9

WPF में आप भी ऐसा कर सकते हैं अगर आप दोनों एक png और रंग VisualBrush साथ (इस ब्रश के साथ एक ब्रश परिभाषित करना चाहते हैं - प्रदर्शन हिट की वजह से और काफी कुछ अन्य ब्रश Windows स्टोर ऐप्स में उपलब्ध नहीं हैं ,

<Window.Resources> 
    <VisualBrush x:Key="myBrush"> 
     <VisualBrush.Visual> 
      <Grid> 
       <Rectangle Fill="Red"/> 
       <Image Source="troll.png"/> 
      </Grid> 
     </VisualBrush.Visual> 
    </VisualBrush> 
</Window.Resources> 
<Grid Background="{StaticResource myBrush}"/> 
0

नहीं वास्तव में अपने प्रश्न का उत्तर है, लेकिन एक समान दृश्य प्रभाव प्राप्त करने के लिए आप: जब ब्रश यहाँ प्रतिपादन) एक बुनियादी उदाहरण है, ब्रश काफी कुछ गुण आप के साथ चारों ओर खेल सकते हैं अपनी ग्रिड की पृष्ठभूमि को एक छवि पर सेट करें; और आपके पृष्ठ/विंडो की पृष्ठभूमि को रंग में।

0

एक और ग्रिड के भीतर एक ग्रिड रखो। बाहरी ग्रिड में सॉलिडकॉलर ब्रश होता है, और आंतरिक ग्रिड में आंशिक रूप से पारदर्शी छविब्रश होता है।

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