0

次のようなカスタム コントロール タイプ<Grid> ... </Grid>と Grid.BitmapEffect プロパティがあります。このコントロール (グリッド) の BitmapEffetc を C# コード (イベントなど) で変更するにはどうすればよいですか?

コード サンプル - カスタム コントロールの一部:

[...]
<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>
[...]

次に Window.xaml で:

<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
}
4

3 に答える 3

2
myGrid.BitmapEffect = null;

PS: BitmapEffectは廃止されたと見なされ、代わりに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>

コードビハインド:

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.BitmapEffectControl1 のBitmapEffectではなく、Gridの BitmapEffect を変更する必要があることに注意してください。

于 2009-12-16T13:08:31.457 に答える
1

さまざまな効果がここにリストされています:異なる BitmapEffect

于 2011-10-21T10:11:11.483 に答える
1

わかりました!DepencyProperty 'GlowSize' を追加し、それを介してグローのサイズを変更するだけでした。:)完璧に動作します。

于 2009-12-16T15:24:10.497 に答える