0

次のコードがあり、画像をクリックしても Click イベントが発生しません。画像の外側をクリックすると、ボタン クリック イベントが発生します。

XAML:

<Grid x:Name="LayoutRoot" Background="White">
    <Button x:Name="btnMain" Background="Purple" >             
        <StackPanel x:Name="spButtonPanel" Background="Black">
            <telerik:RadImageEditor x:Name="imgButtonImage" />
            <TextBlock x:Name="tbButtonText" />
        </StackPanel>
    </Button>
</Grid>

CS:

this.btnMain.Click += new RoutedEventHandler(btnMain_Click);
this.imgButtonImage.MouseLeftButtonDown += new MouseButtonEventHandler(imgButtonImage_Click);
this.spButtonPanel.MouseLeftButtonDown += new MouseButtonEventHandler(spButtonPanel_Click);  

x_Click イベントでは、単純に MessageBox.Show("Button clicked"); です。xはbtn_Mainなどです...

画像をクリックしても imgButtonImage_Click は起動しません。ZIndex を無駄に変更しようとしました。

4

4 に答える 4

1

JSimoes のヘルプで解決しました。

        BitmapImage bi = new BitmapImage();
        bi.SetSource(new MemoryStream(imageBytes));
        imgButtonImage.Source = bi;

ありがとう。

于 2012-12-05T14:47:36.973 に答える
1

<telerik:RadImageEditor x:Name="imgButtonImage" />ボタン内にあるスタックパネル内で使用しているのはなぜですか? ボタン内に画像エディターを配置することは、私には意味がありません。ボタン内にテキストを含む画像を表示したい場合は、次のようなものを使用できます。

<Button Style="{StaticResource MyButtonStyle}">  
    <StackPanel>  
        <Image Source="{Binding ...}  Margin="10" />  
        <TextBlock Text="Localizable Text" />  
    </StackPanel>  
</Button>

画像ソースとして base64string を使用するには、次のようにします。

string bgImage64 = //   image stored in string
byte[] binaryData = Convert.FromBase64String(bgImage64);

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = new MemoryStream(binaryData);
bi.EndInit();

imgButtonImage.Source = bi;

このコードをカプセル化し、xaml で直接使用するには、IValueConverterを作成して次のようなものを使用できます。<Image Source="{Binding ...stringDataSource..., Converter={StaticResource MyBase64ImageConverter}}"/>

于 2012-12-05T12:44:11.917 に答える
0

xamlにイベントを追加してみてください

<Button x:Name="btnMain" Background="Purple" Click="btnMain_Click" >           
于 2012-12-05T13:20:58.913 に答える
0

Telerik RadImageEditor コントロールはわかりませんが、マウスのバブリング イベントを処理していると思います。たとえば、代わりにトンネリング イベント ( で始まるイベント名Preview)を使用する必要がありますPreviewMouseLeftButtonDown

于 2012-12-05T12:36:54.560 に答える