将画布转换为WPF中的按钮

时间:2014-09-29 17:51:12

标签: c# wpf xaml

我在画布中设计了一个按钮,现在我想将它转换为按钮,使用isPressed或MouseOver属性... 这是画布的XAML代码:

<Canvas x:Name="btnBelep" HorizontalAlignment="Left" Height="69.416" VerticalAlignment="Top" Width="252" Grid.Row="1" Margin="1,1.125,0,0" d:IsLocked="True">
    <Path x:Name="Rectangle_6" Data="F1M1,2C1,2 251.103,2 251.103,2 251.103,2 251.103,70 251.103,70 251.103,70 1,70 1,70 1,70 1,2 1,2z" Fill="#FFE3E3E3" Height="69.395" Width="252" Stretch="Fill"/>
    <TextBlock x:Name="Beléptetés1" Foreground="#FF3F3E3E" FontSize="16" FontFamily="Arial" IsHyphenationEnabled="True" LineStackingStrategy="BlockLineHeight" Canvas.Left="73.833" LineHeight="16" TextAlignment="Left" TextWrapping="Wrap" Text="Beléptetés" Canvas.Top="25.176"/>
    <Path x:Name="Plus_Sign_In_A_Circular_Outline__Attribute_as_Freepik_from_Flaticon_com" Data="F1M14.234,6.491C14.808,6.491 15.274,6.948 15.274,7.514 15.274,7.514 15.274,12.015 15.274,12.015 15.274,12.015 19.85,12.015 19.85,12.015 20.425,12.015 20.891,12.473 20.89,13.038 20.89,13.603 20.424,14.061 19.85,14.061 19.85,14.061 15.274,14.061 15.274,14.061 15.274,14.061 15.274,18.563 15.274,18.563 15.274,19.128 14.808,19.586 14.234,19.586 13.659,19.586 13.194,19.128 13.194,18.563 13.194,18.563 13.194,14.061 13.194,14.061 13.194,14.061 8.618,14.061 8.618,14.061 8.043,14.061 7.578,13.603 7.578,13.038 7.578,12.473 8.043,12.015 8.618,12.015 8.618,12.015 13.194,12.015 13.194,12.015 13.194,12.015 13.194,7.514 13.194,7.514 13.194,6.948 13.66,6.491 14.234,6.491z M14.234,3.235C8.738,3.235 4.268,7.632 4.268,13.038 4.268,18.444 8.738,22.841 14.234,22.841 19.73,22.841 24.201,18.444 24.201,13.038 24.201,7.632 19.73,3.235 14.234,3.235z M14.234,1.001C20.981,1.001 26.471,6.401 26.471,13.038 26.471,19.675 20.981,25.076 14.234,25.076 7.487,25.076 1.998,19.675 1.998,13.038 1.998,6.401 7.487,1.001 14.234,1.001z" Fill="#FFD76B93" Height="27" Canvas.Left="30.833" Canvas.Top="17.257" Width="28"/>
    <Path x:Name="Shape_3_Copy2" Data="F1M1,3C1,3 1,2 1,2 1,2 251.103,2 251.103,2 251.103,2 251.103,3 251.103,3 251.103,3 1,3 1,3z" Fill="#FFC7C7C7" Height="3" Canvas.Top="66.395" Width="252" Stretch="Fill"/>
</Canvas>

2 个答案:

答案 0 :(得分:2)

Canvas指定为按钮的Content属性:

<Button>
   <Button.Content>
       Awesome Canvas
   </Button.Content>
</Button>

由于Content在没有其他任何内容时被假定为标签,因此您也可以这样做:

<Button>
   Awesome Canvas
</Button>

答案 1 :(得分:1)

将您的画布包裹在Viewbox中并应用于该按钮。视图框将帮助将画布(绝对线)转换为UI面板(相对线)...

<Button>
    <Viewbox>
        <Canvas>
               ....
        </Canvas>
    </Viewbox>
</Button>