2014-05-21 7 views
0

Silverlight 5 앱에는 사용자 정의 컨트롤 내의 버튼을 사용하여 해당 데이터와 연결된 페이지로 이동하는 16x16 png가 있습니다. 따라서 일부 화면에서는이 컨트롤의 여섯 가지 인스턴스가 있습니다. 어떤 이유로 모든 컨트롤이 똑같이 스타일링되었지만 일부 이미지에서는 컨트롤이 선명하게 보이지만 다른 컨트롤에서는 흐리게 보입니다. 일반적으로 화면 상단의 컨트롤이 명확하게 렌더링되는 것처럼 보이지만 가운데 및 아래의 컨트롤은 흐릿한 것처럼 보입니다. 이것은 어떤 관련성이있을 수도 있고 없을 수도 있습니다 ...화면상의 다른 위치에 표시되는 동일한 png 이미지 파일의 정의가 손실 됨 - Silverlight

나는 왜 이것이 일어나고 그것에 대해 무엇을해야하는지에 관해서 난처합니다. 거의 모든 가능한 것들은 WPF와 관련이 있습니다. WPF에는 사용할 수있는 몇 가지 옵션이 더 있습니다. 그것은에 발생하는 사용자들은 단지이 컨트롤은 아니지만이 사람은 가장 널리 사용하고 명백한 예입니다 :

  <VisualState x:Name="Normal"/> 
      <VisualState x:Name="MouseOver"> 
       <Storyboard> 
       <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/> 
       <ColorAnimation Duration="0" To="#F2FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       <ColorAnimation Duration="0" To="#CCFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       <ColorAnimation Duration="0" To="#7FFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       </Storyboard> 
      </VisualState> 
      <VisualState x:Name="Pressed"> 
       <Storyboard> 
       <ColorAnimation Duration="0" To="#FF6DBDD1" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/> 
       <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/> 
       <ColorAnimation Duration="0" To="#D8FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       <ColorAnimation Duration="0" To="#C6FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       <ColorAnimation Duration="0" To="#8CFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       <ColorAnimation Duration="0" To="#3FFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> 
       </Storyboard> 
      </VisualState> 

      <VisualState x:Name="Disabled"> 
       <Storyboard> 
       <DoubleAnimation Duration="0" Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To=".55"/> 
       </Storyboard> 
      </VisualState> 
      </VisualStateGroup> 
      <VisualStateGroup x:Name="FocusStates"> 
      <VisualState x:Name="Focused" /> 
      <VisualState x:Name="Unfocused" /> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 

     <Border x:Name="Background" CornerRadius="3" Background="White" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"> 
      <Grid Background="{TemplateBinding Background}" Margin="1"> 
      <Border Opacity="0" x:Name="BackgroundAnimation" Background="#FF448DCA" /> 
      <Rectangle x:Name="BackgroundGradient" > 
       <Rectangle.Fill> 
       <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"> 
        <GradientStop Color="#FFFFFFFF" Offset="0" /> 
        <GradientStop Color="#F9FFFFFF" Offset="0.375" /> 
        <GradientStop Color="#E5FFFFFF" Offset="0.625" /> 
        <GradientStop Color="#C6FFFFFF" Offset="1" /> 
       </LinearGradientBrush> 
       </Rectangle.Fill> 
      </Rectangle> 
      </Grid> 
     </Border> 

     <ContentPresenter x:Name="contentPresenter" 
          Content="{TemplateBinding Content}" 
          ContentTemplate="{TemplateBinding ContentTemplate}" 
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}"/> 
     <Rectangle x:Name="DisabledVisualElement" RadiusX="3" RadiusY="3" Fill="#FFFFFFFF" Opacity="0" IsHitTestVisible="false" /> 
     <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#FF6DBDD1" StrokeThickness="1"/> 
     </Grid> 
    </ControlTemplate> 
    </Setter.Value> 
</Setter> 

편집 : - 이제다음과 같이 고정Franck이 제안한 링크를 따라 수정했습니다.

namespace PixelSnapper 

{

시스템을 사용하여 ... 오류를 삼켜 ... 오히려 그렇게 한 앱이 어떤 상황에서 그랬던 것처럼 실패를보다 흐릿 이미지를 가지고 그것을 수정; using System.Windows; using System.Windows.Controls; using System.Windows.Media;

public enum PixelSnapType 
{ 
    None, // No snapping 
    Closest, // Snap to closest pixel using Math.Round 
    TopLeft // Snap to integral portion of pixel by casting to int 
} 

public class Snapper : UserControl 
{ 
    public Snapper() 
    { 
     LayoutUpdated += SnapperLayoutUpdated; 
     Snap = PixelSnapType.Closest; 
    } 

    public PixelSnapType Snap { get; set; } 

    private void SnapperLayoutUpdated(object sender, EventArgs e) 
    { 
     if (Content == null) return; 

     if (Snap == PixelSnapType.None) 
     { 
      Content.RenderTransform = null; 
      return; 
     } 

     try 
     { 


      // Remove existing transform so that it is not a part of the calculations 
      if (this.transform != null) 
      { 
       this.transform.X = 0; 
       this.transform.Y = 0; 
      } 

      // Calculate actual location 
      var globalTransform = Content.TransformToVisual(Application.Current.RootVisual) as MatrixTransform; 
       if (globalTransform == null) 
       { 
        return; 
       } 

      var p = globalTransform.Matrix.Transform(Zero); 

      double deltaX = Snap == PixelSnapType.Closest ? Math.Round(p.X) - p.X : (int)p.X - p.X; 
      double deltaY = Snap == PixelSnapType.Closest ? Math.Round(p.Y) - p.Y : (int)p.Y - p.Y; 

      // Set new transform 
      if (deltaX != 0 || deltaY != 0) 
      { 

       if (this.transform == null) 
       { 
        this.transform = new TranslateTransform(); 
        Content.RenderTransform = this.transform; 
       } 

       if (deltaX != 0) 
       { 
        this.transform.X = deltaX; 
       } 

       if (deltaY != 0) 
       { 
        this.transform.Y = deltaY; 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      return; 
     } 

    } 

    private TranslateTransform transform; 
    private static readonly Point Zero = new Point(0, 0); 

} 

}

데이브 Relyea의

원래 의례 : pixel Snapper 당신은 이미지에 SnapsToDevicePixels="True"을 설정해야

답변

1

그렇지 않으면 일부 이미지가

당신도 할 수 있습니다 17x16, 17x17 및 16x17이 될 것입니다 이걸 가지고 놀아 라.

RenderOptions.BitmapScalingMode="HighQuality" 
+0

내가 원했던 - b 유감 스럽지만 유감스럽게도 실버 라이트보다는 WPF에만 해당한다고 말할 수 있습니다. 포스트 실버 라이트에 태그를 붙 였지만 제목을 편집하여 명확하게 만들 것입니다.UseLayoutRounding = True (Silverlight 호환 일종의 동급)이지만 여전히 기쁨이 없습니다. – SteveL

+0

silverlight 용 specialy로 만든 장치 픽셀 클래스를 사용할 수 있습니다. 여기에서 찾을 수 있습니다 (http : // blogs. msdn.com/b/devdave/archive/2008/05/26/pixel-snapping-the-snapper-element.aspx) – Franck

+0

Dave Relyea의 블로그 및 픽셀 스 내퍼 클래스에 대한 링크가있는 주석에 대한 대답으로 표시되었습니다. 약간의 예외 처리 후에 매력을 ... 고마워했습니다! – SteveL