2009-12-16 2 views
0

<Grid> ... </Grid> 및 Grid.BitmapEffect 속성과 같은 사용자 지정 컨트롤 유형이 있습니다. C# 코드 (예 : 이벤트)를 통해이 컨트롤 (그리드)에서 BitmapEffetc를 어떻게 변경합니까?C# 코드를 통해 사용자 지정 WPF 컨트롤에서 BitmapEffect를 변경하는 방법

코드 샘플 - 사용자 지정 컨트롤의 일부 : Window.xaml에서 다음

[...] 
<Grid Background="#FFE5AA"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="62*"/>    
     <RowDefinition Height="15*"/> 
     <RowDefinition Height="23*"/> 
    </Grid.RowDefinitions> 

    <Grid.BitmapEffect> 
     <OuterGlowBitmapEffect GlowColor="#459E5A" GlowSize="13" Noise="0" Opacity="0.9" /> 
    </Grid.BitmapEffect> 

    <Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" BorderBrush="#F5B903" BorderThickness="1,1,1,1" > 
    </Border> 
[...] 

:

<controls:MyControl Name="Control1" Cursor="Hand" MouseDown="Control1_MouseDown" /> 

그리고 C#에서 :

private void Control1_MouseDown(object sender, MouseButtonEventArgs e) 
{ 
    //there i want to change Control1.BitmapEffect 
} 

답변

1

확인해 보겠습니다. 나는 DepencyProperty 'GlowSize'를 추가하고 단순히 그것을 통해 빛의 크기를 변경했습니다. :) 완벽하게 작동합니다.

2
myGrid.BitmapEffect = null; 

PS : 참고 BitmapEffect은 쓸데없는 것으로 간주되며 th Effect에 대신 사용해야합니다.


여기에 완벽하게 정상적으로 (여기서 내 컴퓨터에) 작동 샘플을 기반으로 예제 : 최대한 빨리 그리드 내에서 클릭과 같은 효과가 사라집니다.

XAML :

<Window x:Class="WpfCsApplication1.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Window1" Height="300" Width="300"> 

<Grid Background="#FFE5AA" Margin="10" MouseDown="Grid_MouseDown" x:Name="myGrid"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="62*"/> 
     <RowDefinition Height="15*"/> 
     <RowDefinition Height="23*"/> 
    </Grid.RowDefinitions> 
    <Grid.BitmapEffect> 
     <OuterGlowBitmapEffect GlowColor="#459E5A" GlowSize="13" Noise="0" Opacity="0.9" /> 
    </Grid.BitmapEffect> 
    <Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" BorderBrush="#F5B903" BorderThickness="1,1,1,1" > 
     <TextBlock>Test</TextBlock> 
    </Border> 
</Grid> 
</Window> 

이 Codebehind가 : 당신의 예에서

public partial class Window1 : Window { 
    public Window1() { 
     InitializeComponent(); 
    } 

    private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { 
     myGrid.BitmapEffect = null; 
    } 
} 

당신이 쓰기 : //there i want to change Control1.BitmapEffect. Grid의 BitmapEffect를 변경해야하며 BitmapEffect는 Control1이 아니라 변경해야합니다.

+0

효과가 없습니다. – Kamilos

+0

방금 ​​해봤지만 제대로 작동합니다. 문제를 재현 할 수있는 간단한 예를 제공 할 수 있습니까? – Heinzi

+0

좋습니다. – Kamilos

관련 문제