1
테두리 요소 안에 중첩 된 TextBlock에 대한 MouseEnter 이벤트를 발생시키면서 이미지의 특정 부분을 잘라내려고합니다 (CSS 'background-position : -1100px - 24 픽셀)을 테두리 요소의 배경으로 배치합니다. 코드가 SOFAR 다음과 같은 :Silverlight에서 MouseEnter (hover) 이벤트에 대한 배경 이미지 위치 지정
XAML
<Border Margin="42,9,0,0">
<TextBlock Style="{StaticResource MenuItem}" Name="metallicaButton" MouseEnter="metallicaButton_MouseEnter" Text="metallica" />
</Border>
C#
private void metallicaButton_MouseEnter(object sender, MouseEventArgs e)
{
/*
ImageBrush img = new ImageBrush();
img.ImageSource = new BitmapImage(new Uri(@"Images/frame.png", UriKind.Relative)); ;
img.Stretch = Stretch.None;
need to develop a subsitute for CSS code:
span:hover{background-position: -1100px -24px;}
...something more versatile than:
img.AlignmentX = AlignmentX.Center;
img.AlignmentY = AlignmentY.Bottom;
((Border)metallicaButton.Parent).Background = img;
OR
Rect r = Rect.Empty;
r.X = -1100;
r.Y = -24;
RectangleGeometry g = new RectangleGeometry();
g.Rect = r;
Image src = new Image();
src.Source = new BitmapImage(new Uri(@"Images/frame.png", UriKind.Relative)); ;
src.Clip = g;
is there a way to do this:
((Border)((TextBlock)sender).Parent).Background = src;
*/
}
이 할 수있는 방법이 있나요?
아마도 [답변] (http://stackoverflow.com/a/774386/1246606) 도움이됩니다. 나는 그들을 거기에서 되풀이하고 싶지 않다. – ostapische