按钮图像未显示在网格列1中 [英] Button image does not show up in grid column 1

查看:53
本文介绍了按钮图像未显示在网格列1中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,当Grid.Column =" 1"时,我感到很沮丧。为按钮设置,图像不会出现,但是当它被设置为"0"时,图像被设置为"0"。它确实。任何线索?

I have the following code and it frustrates me that when Grid.Column="1" is set for the button, the image does not shop up, but when it is set to "0" it does. Any leads?

            <phone:PanoramaItem x:Name="Search" Header="search">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="350"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBox x:Name="Query" Text="" Grid.Column="0" />
                    <Button x:Name="btnSearch" Grid.Column="1" Click="btnSearch_Click" BorderThickness="1">
                        <Button.Background>
                        <ImageBrush ImageSource="/Assets/icons/feature.search.png" Stretch="None"/>
                        </Button.Background>
                    </Button>
                </Grid>
            </phone:PanoramaItem>




 


 

推荐答案

问题是你的Button没有内容而没有设置宽度。

The problem is that your Button has no content and not width set.

因此在布局系统测量时会分配0像素的宽度。

Therefore is gets 0 pixels width assigned from the layout system when it's measured.

2解决方案:


  1. 您可以使用固定的按钮(例如< Button 宽度
    =" 50" ...>
  2. 不是将图片设置为背景,而是使用按钮的内容
  1. You can give the button a fixed with (e.g. <Button Width = "50" ...>
  2. Instead of setting the image as background use it a Content of the Button.


                    <Button x:Name="btnSearch" Grid.Column="1" Click="btnSearch_Click" BorderThickness="1">
                        <Image ImageSource="/Assets/icons/feature.search.png" Stretch="None"/>
                    </Button>


这篇关于按钮图像未显示在网格列1中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆