2010-03-24 15 views
10

मैं आजकल बना रहे बटनों के नियंत्रण नियंत्रण पर फैशनेबल "रिफ्लेक्स" प्रभाव को दोहराने की कोशिश कर रहा हूं।आयताकार ज्यामिति सापेक्ष आयामों के साथ ... कैसे?

मूल विचार एक आयताकार को सफेद से पारदर्शी भरने के साथ एक आयताकार बनाना है और फिर उस अर्द्ध पारदर्शी आयताकार को आयताकारमिति के साथ क्लिप करना है।

समस्या यह है कि मुझे नहीं पता कि एक सापेक्ष आयताकार ज्यामिति को कैसे परिभाषित किया जाए। मैं एक बड़े मूल्य (1000) को परिभाषित करके चौड़ाई के आसपास काम किया, लेकिन ऊंचाई एक समस्या है। उदाहरण के लिए, यह 200 ऊंचाई वाली बटनों के लिए अच्छा काम करता है, लेकिन छोटे बटन के लिए कुछ भी नहीं करता है।

कोई भी विचार?

  <Rectangle RadiusX="5" RadiusY="5" StrokeThickness="1" Stroke="Transparent"> 
       <Rectangle.Fill> 
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.55"> 
         <GradientStop Color="#66ffffff" Offset="0.0" /> 
         <GradientStop Color="Transparent" Offset="1.0" /> 
        </LinearGradientBrush> 
       </Rectangle.Fill> 
       <Rectangle.Clip> 
        <RectangleGeometry Rect="0,0,1000,60" /> 
       </Rectangle.Clip> 
      </Rectangle> 

उत्तर

11

आप एक MultiBinding और एक नया IMultiValueConverter के साथ ऐसा कर सकता है:

public class RectangleConverter : IMultiValueConverter 
{ 
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 
{ 
     // you can pass in the value to divide by if you want 
     return new Rect(0, 0, (double)values[0], (double)values[1]/3.33); 
    } 

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 
    { 
     throw new NotSupportedException(); 
    } 
} 

और इसलिए अपने XAML में की तरह इस्तेमाल किया:

<lcl:RectangleConverter x:Key="rectConverter" /> 

... 

<RectangleGeometry> 
    <RectangleGeometry.Rect> 
     <MultiBinding Converter="{StaticResource rectConverter}"> 
      <Binding Path="ActualWidth" RelativeSource="{RelativeSource AncestorType={x:Type Button}}" /> 
      <Binding Path="ActualHeight" RelativeSource="{RelativeSource AncestorType={x:Type Button}}" /> 
     </MultiBinding> 
    </RectangleGeometry.Rect> 
</RectangleGeometry> 
+0

यह मुझसे कहता है: 'नाम "MultiBinding" नामस्थान में मौजूद नहीं है "http://schemas.microsoft.com/client/2007"। ' –

+0

मुझे नहीं पता कि xaml नेमस्पेस क्या है, लेकिन आपका 'http: // schemas.microsoft.com/winfx/2006/xaml/प्रस्तुति' होना चाहिए। –

+0

मेरे पास है: 'xmlns =" ​​http://schemas.microsoft.com/winfx/2006/xaml/presentation "' और 'xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml "'। मेरे समाधान में एक बार "2007" नहीं है। यह एक विंडोज फोन 8 एप्लीकेशन है। –

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