简体   繁体   English

如何在按钮中有多个内容?

[英]How to have multiple content in button?

This is my app:这是我的应用程序: 在此处输入图像描述 This is my Xaml:这是我的 Xaml:

    <Grid Name="grd1" Width="202" Margin="-5,0,0,0" Visibility="Visible">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="16*"/>
            <ColumnDefinition Width="31*"/>
        </Grid.ColumnDefinitions>
        <Button VerticalAlignment="Top" Height="43" HorizontalAlignment="Right" Width="196" Grid.ColumnSpan="2" Margin="-8,0,0,0">
            <Button.Content>
                <CheckBox Name="chk_shortcut_1" IsChecked="False" Checked="chk_shortcut_1_Checked" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="165,-19,0,0" />
            </Button.Content>
        </Button>
        <Button VerticalAlignment="Top" Height="43" HorizontalAlignment="Right" Width="196" Margin="-8,48,0,0" Grid.ColumnSpan="2">
            <CheckBox Name="chk_shortcut_2" IsChecked="False" Checked="chk_shortcut_1_Checked" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="165,-19,0,0" />
        </Button>
        <Button VerticalAlignment="Top" Height="43" HorizontalAlignment="Right" Width="196" Margin="-8,96,0,0" Grid.ColumnSpan="2">
            <CheckBox Name="chk_shortcut_3" IsChecked="False" Checked="chk_shortcut_1_Checked" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="165,-19,0,0" />
        </Button>
    </Grid>
</ListBox>
How can I have image and text and CheckBox inside a Button? 如何在 Button 中包含图像和文本以及 CheckBox? Because I want to clone button by checking checkboxes in another listbox later 因为我想稍后通过选中另一个列表框中的复选框来克隆按钮

As far as I know, the button that you need is not a pure component, it's a complex control and need to be implemented by yourself or use third party components like Telerik.据我所知,你需要的按钮不是纯组件,而是复杂的控件,需要自己实现或者使用Telerik等第三方组件。 But a good answer would be: Create a user control.但一个好的答案是:创建一个用户控件。 Use a container component and like Grid and split it to 2 section, left and right.使用容器组件,如 Grid 并将其分成左右两部分。 At the left side you should add an image component and right side should contain a readonly text or label.在左侧,您应该添加一个图像组件,右侧应该包含一个只读文本或 label。 define events to be clickable and configure other behaviors as you need.将事件定义为可点击并根据需要配置其他行为。 something like below code can be useful but need to spend more time and work on.类似下面的代码可能很有用,但需要花费更多时间和精力。

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="277*"/>
        <ColumnDefinition Width="523*"/>
    </Grid.ColumnDefinitions>
    <Image HorizontalAlignment="Left" Grid.Column="0" Height="100" Margin="103,225,0,0" VerticalAlignment="Top" Width="100"/>
    <Label Content="Label" Grid.Column="1" HorizontalAlignment="Left" Margin="273,238,0,0" VerticalAlignment="Top"/>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM