2009-11-25 7 views
30

मैंने अपने xaml में किसी विशिष्ट आइटम की सीमा को परिभाषित करने वाला एक स्थिर संसाधन बनाया है, लेकिन मुझे प्रत्येक पक्ष के लिए एक अद्वितीय रंग परिभाषित करने का एक अच्छा तरीका नहीं मिल रहा है!प्रत्येक कोने के लिए एक अलग ब्रश रंग के साथ सीमा बनाएं

XAML:

<Border Style="{StaticResource SidePanelBorder}"> 
     <!-- rest of the xaml --> 
</Border> 

StaticResource:

<Style x:Key="SidePanelBorder"> 
    <Setter Property="Control.BorderBrush" Value="#FF363636" /> 
    <Setter Property="Control.BorderThickness" Value="1" /> 
</Style> 

लेकिन मैं सीमा के दोनों ओर के लिए एक रंग है, और अंततः भी एक अलग सीमा मोटाई निर्धारित करना चाहते हैं।

ऐसा करने से कोई भी अच्छी तकनीकें?

+0

मैं सीमा –

उत्तर

49

उपवर्गीकरण बिना यह करने के लिए कोई आसान तरीका नहीं है बहुत hacky लगता है, लेकिन आप सीमाओं के भीतर सीमाओं को परिभाषित कर सकता है, और बनाने के लिए केवल 1 पक्ष मोटाई की है। उदाहरण के लिए

<Border BorderThickness="0,0,0,10" BorderBrush="Green"> 
    <Border BorderThickness="0,0,10,0" BorderBrush="Blue"> 
     <Grid> 
      <Button>Hello</Button> 
     </Grid> 
    </Border> 
</Border> 

नीचे और सही करने के लिए नीले रंग के बॉर्डर पर एक हरे रंग की सीमा देना होगा। हालांकि Xaml का सबसे सुंदर टुकड़ा नहीं है।

+0

यह वही है जो मैंने अपने स्वयं के सबसे अच्छे समाधान के रूप में पाया। इस तरह के सरल के लिए 2 सीमाओं को पेश करना आवश्यक नहीं होना चाहिए, लेकिन मुझे लगता है कि मुझे आपके समाधान के लिए जाना होगा! धन्यवाद –

+5

क्या यह गोलाकार कोनों के साथ काम करेगा? – eriksmith200

2

अपने स्वयं के नियंत्रण लिख रहे हैं या सीमा

+5

हम्म का उपयोग करके एक इन्सेट प्रभाव बनाना चाहता हूं, यह शर्म की बात है! एचटीएमएल और सीएसएस में जितना आसान हो सकता था, जहां आपके पास सीमा-शीर्ष, सीमा-दाएं और इतने पर हैं! –

9

आपके पास एक डॉकपैनल हो सकता है और इसमें 4 सीमाएं लगाई जा सकती हैं, प्रत्येक अलग-अलग पक्ष में डॉक की जाती है। की तरह:

<DockPanel LastChildFill="true"> 
    <Border DockPanel.Dock="Left" Background="Red"/> 
    <Border DockPanel.Dock="Top" Background ="Blue"/> 
    <Border DockPanel.Dock="Right" Background ="Yellow"/> 
    <Border DockPanel.Dock="Bottom" Background ="Green"/> 
    <Grid> 
    ...........your control here 
    </Grid> 
</DockPanel> 
+2

दिलचस्प दृष्टिकोण। – Tower

4

आप एक ग्रिड का उपयोग करते हैं तो आप को प्राप्त करने के लिए एक ही प्रभावित करते हैं एक दूसरे पर सीमा के ओवरले के हो सकता है। बस अन्य सीमा मोटाई 0.

<UserControl.Resources> 
     <Style x:Key="GreenBorder" TargetType="Border"> 
      <Setter Property="BorderBrush" Value="Green" /> 
      <Setter Property="BorderThickness" Value="1,1,1,0" />   
     </Style> 
     <Style x:Key="RedBorder" TargetType="Border"> 
      <Setter Property="BorderBrush" Value="Red" /> 
      <Setter Property="BorderThickness" Value="0,0,0,1" /> 
     </Style> 
    </UserControl.Resources> 

    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Border Grid.Column="0" Grid.Row="0" Style="{StaticResource GreenBorder}"> 
      <!-- Content goes here --> 
     </Border> 
     <Border Grid.Column="0" Grid.Row="0" Style="{StaticResource RedBorder}"> 
     </Border> 
    </Grid> 

यह बाईं, ऊपर और सही सीमाओं करने के लिए एक ग्रीन सीमा दे देंगे, हो सीमा रंग आप दिखाने के लिए और करना चाहते हैं की सीमा मोटाई लेकिन करने के लिए एक लाल सीमा सेट ग्रिड सेल की निचली सीमा।

20

एक अन्य समाधान, एक सीमा है और एक VisualBrush का उपयोग कर स्थापित करने के लिए अनुमति देता है सीमा के CornerRadius और BorderThickness:

<Border BorderThickness="10" CornerRadius="10" HorizontalAlignment="Right" Height="150" VerticalAlignment="Bottom" Width="150" Margin="0,0,92.666,42.667"> 
    <Border.BorderBrush> 
     <VisualBrush> 
      <VisualBrush.Visual> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition/> 
         <RowDefinition/> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition/> 
         <ColumnDefinition/> 
        </Grid.ColumnDefinitions> 

        <Path x:Name="ColoredBorderLeft" Data="M0,0 L0,0 1,0.5 L1,0.5 0,1" Fill="Blue" Stretch="Fill" Grid.RowSpan="2"/> 
        <Path x:Name="ColoredBorderRight" Data="M1,0 L1,0 0,0.5 L0,0.5 1,1" Fill="Red" Stretch="Fill" Grid.Column="1" Grid.RowSpan="2"/> 
        <Path x:Name="ColoredBorderTop" Data="M0,0 L0,0 0.5,1 L0.5,1 1,0" Fill="Green" Stretch="Fill" Grid.ColumnSpan="2"/> 
        <Path x:Name="ColoredBorderBottom" Data="M0,1 L0,1 0.5,0 L0.5,0 1,1" Fill="Yellow" Stretch="Fill" Grid.Row="1" Grid.ColumnSpan="2"/> 
       </Grid> 
      </VisualBrush.Visual> 
     </VisualBrush> 
    </Border.BorderBrush> 
</Border> 
  • ग्रिड सीमा में "के माध्यम से धक्का" करने के लिए त्रिकोण पथ के सुझावों को रोकने के लिए की जरूरत है ।
  • पथ नाम का उपयोग डेटा बाइंडिंग के लिए या कोड के पीछे से रंग को सेट करने के लिए किया जा सकता है।
+0

बहुत अच्छा, और गोलाकार कोनों के साथ काम करता है –

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