首页 > 解决方案 > 如何使用 DataBinding 处理事件双击?

问题描述

我有一个项目,我想在双击按钮时显示一个形状ShapeDesigner.xaml,我该怎么做。太感谢了。这是 .xaml 代码GridMainWindow.xamlShapeToolUI.xaml

形状设计器.xaml

<Canvas x:Name="Canvas">
    <!-- Draw circle-->
    <ContentControl x:Name="Circle"
        Width="366" Height="312" Canvas.Top="50" Canvas.Left="50"
        MinWidth="50" MaxWidth="200" MinHeight="50" MaxHeight="200"
                Template="{StaticResource DesignShape}" RenderTransformOrigin="3.005,2.555">
        <Ellipse Fill="Red"
                 IsHitTestVisible="False"></Ellipse>
        
    </ContentControl>
</Canvas>

主窗口.xaml

<Grid Background="#FFBCE6FF" >
    // I want to display Canvas in ShapeDesigner in here when double-clicked button in ShapeToolUI
</Grid>

形状工具UI.xaml

<Grid Background="White">
    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" >
        <StackPanel Background="#FFBCE6FF">
            <Button  MouseDoubleClick="DisplayRhombus"
                Margin="10,40,10,0" Height="91" Width="100" BorderBrush="#FFBCE6FF" Foreground="#FFBCE6FF">
                <Button.Background>
                    <ImageBrush ImageSource="rhombus.png"/>
                </Button.Background>
            </Button>
</Grid>

非常感谢<3

标签: c#wpfxamldata-binding

解决方案


您的“DisplayRhombus”在哪里定义?如果不是,则需要先定义。并从该函数内部调用“Circle”。


推荐阅读